pocketlang/tests/lang/class.pk
2021-06-21 12:13:37 +05:30

37 lines
536 B
Plaintext

## TODO: Implement ctor with va arg to
## initialize, fields.
class _Vec
x = 0
y = 0
end
def Vec(x, y)
ret = _Vec()
ret.x = x; ret.y = y
return ret
end
def vecAdd(v1, v2)
return Vec(v1.x + v2.x,
v1.y + v2.y)
end
v1 = Vec(1, 2); assert(v1.x == 1 and v1.y == 2)
v2 = Vec(3, 4); assert(v2.x == 3 and v2.y == 4)
v3 = vecAdd(v1, v2)
assert(v3.x == 4 and v3.y == 6)
class Test
fn = null
val = Vec(12, 32)
end
test = Test()
test.fn = to_string
res = test.fn(test.val)
assert(res == "[_Vec: x=12, y=32]")