samples: add Terra samples

source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
Bayu Aldi Yansyah
2016-01-28 11:22:27 +07:00
parent e32a837fb2
commit 9b8b39f444
370 changed files with 11921 additions and 0 deletions

View 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)