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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
use core:debug;
use core:geometry;
// Make sure operators are properly defined.
/**
* A value that only defines 'less than'. All operators should be present as well.
*/
value LessOp {
init(Int v) {
init() { v = v; }
}
Bool <(LessOp o) {
return v < o.v;
}
private Int v;
}
Bool opLT(Int a, Int b) {
LessOp(a) < LessOp(b);
}
Bool opGT(Int a, Int b) {
LessOp(a) > LessOp(b);
}
Bool opLTE(Int a, Int b) {
LessOp(a) <= LessOp(b);
}
Bool opGTE(Int a, Int b) {
LessOp(a) >= LessOp(b);
}
Bool opEQ(Int a, Int b) {
LessOp(a) == LessOp(b);
}
Bool opNEQ(Int a, Int b) {
LessOp(a) != LessOp(b);
}
Bool opActorEQ(DbgActor a, DbgActor b) {
a is b;
}
Bool opActorNEQ(DbgActor a, DbgActor b) {
a !is b;
}
/**
* Class that provides a value 'val' that is accessed through getters and setters (called properties
* in some languages).
*/
class Property {
init() {
init() { v = 10; }
}
Int plain() {
v;
}
void plain(Int to) {
v = to;
}
Int val() {
v;
}
assign val(Int to) {
v = to;
}
assign set(Int to) {
v = to;
}
private Int v;
}
Int testSetter() {
Property p;
p.set = 20;
p.val;
}
Int testSetterPair() {
Property p;
p.val = 20;
p.val;
}
Int testNoSetter() {
Property p;
// Should *not* work.
p.plain = 20;
p.plain;
}
Float testSetterCpp() {
// Setters declared inside C++.
Rect x(0, 0, 100, 100);
x.size = Size(50, 50);
x.p1.x;
}
|