mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
42
samples/Terra/method.t
Normal file
42
samples/Terra/method.t
Normal file
@@ -0,0 +1,42 @@
|
||||
--the zero line
|
||||
struct A { b : B } and
|
||||
struct B {a : int, b : int}
|
||||
|
||||
B.methods.foo = terra(b : B)
|
||||
return b.a
|
||||
end
|
||||
terra bar()
|
||||
var b = B { 1,2 }
|
||||
return b:foo()
|
||||
end
|
||||
|
||||
|
||||
B.methods.foo2 = terra(b : &B)
|
||||
b.a = 6
|
||||
end
|
||||
|
||||
terra bar2()
|
||||
var b = B { 1,2 }
|
||||
b:foo2()
|
||||
return b.a
|
||||
end
|
||||
|
||||
B.methods.foo3 = terra(b : B)
|
||||
return b.a
|
||||
end
|
||||
|
||||
terra bar3()
|
||||
var b = B { 1,2 }
|
||||
return (&b):foo3()
|
||||
end
|
||||
terra bar4()
|
||||
var b = B { 1,2 }
|
||||
(&b):foo2()
|
||||
return b.a
|
||||
end
|
||||
|
||||
test = require("test")
|
||||
test.eq(bar(),1)
|
||||
test.eq(bar2(),6)
|
||||
test.eq(bar3(),1)
|
||||
test.eq(bar4(),6)
|
||||
Reference in New Issue
Block a user