aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-07-04 13:37:23 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-07-04 13:37:23 -0400
commit22063462a90b5c290f5f71319b259fca80da8097 (patch)
tree67d403f893415de9202477608ae9972b9171df88 /test
parentdc1616a3bf7d075e0b50f783313ea6a5b1076fb4 (diff)
Add __length and __negative metamethods
Diffstat (limited to 'test')
-rw-r--r--test/metamethods.tm13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/metamethods.tm b/test/metamethods.tm
index 97d9e5eb..26a5abd6 100644
--- a/test/metamethods.tm
+++ b/test/metamethods.tm
@@ -17,6 +17,12 @@ struct Vec2(x,y:Int):
func __mul4(a,b:Vec2; inline)->Vec2:
return Vec2(a.x*b.x, a.y*b.y)
+ func __negative(v:Vec2; inline)->Vec2:
+ return Vec2(-v.x, -v.y)
+
+ func __length(v:Vec2; inline)->Int:
+ return 2
+
func main():
>> x := Vec2(10, 20)
>> y := Vec2(100, 200)
@@ -36,3 +42,10 @@ func main():
= Vec2(x=11, y=22)
>> x *= Vec2(10, -1)
= Vec2(x=110, y=-22)
+
+ >> x = Vec2(1, 2)
+ >> -x
+ = Vec2(x=-1, y=-2)
+ >> #x
+ = 2
+