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:
32
samples/Terra/terralua.t
Normal file
32
samples/Terra/terralua.t
Normal file
@@ -0,0 +1,32 @@
|
||||
function dog(...)
|
||||
print("Hi. This is Dog.",...)
|
||||
end
|
||||
|
||||
terra foo()
|
||||
dog()
|
||||
end
|
||||
|
||||
terra passanarg()
|
||||
dog(3,4,5,nil)
|
||||
end
|
||||
|
||||
function takesastruct(a)
|
||||
print(a.a,a.b)
|
||||
a.a = a.a + 1
|
||||
end
|
||||
struct A { a : int , b : double }
|
||||
terra passastruct()
|
||||
var a = A {1,3.4}
|
||||
--takesastruct(a) luajit doesn't like having structs passed to its callbacks by value?
|
||||
var b = a.a
|
||||
takesastruct(&a)
|
||||
var c = a.a
|
||||
return b + c
|
||||
end
|
||||
|
||||
foo()
|
||||
passanarg()
|
||||
|
||||
local test = require("test")
|
||||
|
||||
test.eq(passastruct(),3)
|
||||
Reference in New Issue
Block a user