blob: 61d1956a87334511319aca1cc46647ca421aa3e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
; Basic variable declaration with and without default values. The type could be
; inferred, but can also be manually specified.
let a: str
let b: f64
let c:int = 20
; No infix '=', instead we use `set` to bind values.
set a = "hello"
set b = 1.2
set c = (1 + 2 - 3)
; Struct definitions.
struct vec {
x: f32
y: f32
z: f32
}
; Default values are allowed, including const expressions.
struct person {
name: str = "joe"
age: int = 18 * 2
}
; We can use the dot operator to access fields.
let player_a: person
set player_a.name = "alex"
set player_a.age = 32
let player_b = player_a
; Anonymous structs can also be declared inline.
let user: { id: u64 name: str }
set user.id = 10
set user.name = "haxor"
; We can have anonymous struct fields.
struct entity {
pos: vec
vel: vec
attr: {
id: u64
name: str
}
}
; Symbols followed by curly braces output struct literals.
let particle = entity {
; Two ways of initializing inner fields.
pos = vec { x = 1 y = 2 }
attr.id = 1
attr.name = "particle"
; Missing initialization fields default to zero.
vel = vec { y = -3 }
}
; We can have static arrays and have indexed access.
let numbers: u32[0xff]
set numbers[0] = 32
set numbers[1] = 42
; Arrays are syntactic sugar for pointers (@).
let ptr:@u32 = numbers
set ptr[10] = 33
; Strings hold a .mem and .size fields with the number of bytes it holds.
let hello: str = "hello world"
set c[1] = 'a' ; "hallo world"
|