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:
19
samples/Terra/simpleapply.t
Normal file
19
samples/Terra/simpleapply.t
Normal file
@@ -0,0 +1,19 @@
|
||||
struct Vec { data : int[4] }
|
||||
Vec.metamethods.__apply = terra(self : &Vec, i : int)
|
||||
return self.data[i]
|
||||
end
|
||||
|
||||
struct Vec2 { data : int[4] }
|
||||
Vec2.metamethods.__apply = macro(function(self,b)
|
||||
return `self.data[b]
|
||||
end)
|
||||
|
||||
terra bar()
|
||||
var a = Vec { array(1,2,3,4) }
|
||||
var b = Vec2 { array(1,2,3,4) }
|
||||
b(2) = b(2) + 1
|
||||
return b(2) + a(2)
|
||||
end
|
||||
|
||||
local test = require("test")
|
||||
test.eq(bar(),7)
|
||||
Reference in New Issue
Block a user