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

42
samples/Terra/includec.t Normal file
View File

@@ -0,0 +1,42 @@
local c = terralib.includec("mytest.h")
terra foo()
var a : int = 3
return c.myfoobarthing(1,2,3.5,&a) + a
end
terra bar()
return c.myotherthing(4,5)
end
terra bar2()
return c.myfnptr(bar)
end
terra bar3()
var a : c.size_t = 3
return a
end
terra bar4()
var opaquething : c.MyStruct2
var my = c.MyStruct { 3, 4}
return my.a + my.b
end
terra writefile()
c.printf("%f %f %f\n",3.0,4.0,5.0)
var f = c.fopen("afile.txt","w")
c.fputs("a string\n",f)
c.fclose(f)
end
local test = require("test")
test.eq(foo(),15)
test.eq(c.myotherthing(1,2),3)
test.eq(bar2(),9)
test.eq(bar3(),3)
test.eq(bar4(),7)
writefile()