-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstruct.ptrs
58 lines (47 loc) · 933 Bytes
/
struct.ptrs
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
import puts, printf, gettimeofday;
struct Foo
{
//struct can have field-,
value = 42;
//array-
myByteArray: u8[128];
//var-array-
myValues: var[42];
//and function-members
dump()
{
puts("$this - ${this.value}");
}
//there is also a 'constructor' and 'destructor'
constructor(a, b = 0)
{
if(a)
this.value = a + b;
}
//and a few special operators you can overload (see the language docs for more)
operator this[name]
{
printf("getting property %s", name);
return name;
}
operator this(a, b, c = 3)
{
return a + b + c;
}
};
var val = new Foo();
val.dump();
printf("val.foo = %s\n", val.foo);
//printf("val(1337, 10) = %d\n", val(1337, 10));
val.dump();
delete val;
//C compatible structs
struct Time
{
seconds : i64;
microseconds : i32;
};
var now = new Time();
gettimeofday(now, null);
printf("milliseconds since epoch: %lld\n", now.seconds * 1000 + now.microseconds / 1000);
delete now;