slige/examples/generic_array.slg
2025-01-17 11:50:14 +01:00

20 lines
499 B
Plaintext

fn array_new<T>() -> [T] #[builtin(ArrayNew)] {}
fn array_push<T>(array: [T], value: T) #[builtin(ArrayPush)] {}
fn array_length<T>(array: [T]) -> int #[builtin(ArrayLength)] {}
fn array_at<T>(array: [T], index: int) -> string #[builtin(ArrayAt)] {}
fn main() {
let strings = array_new::<string>();
array_push::<string>(strings, "hello");
array_push::<string>(strings, "world");
let ints = array_new::<int>();
array_push::<int>(ints, 1);
array_push::<int>(ints, 2);
}