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:
35
samples/Terra/cunion2.t
Normal file
35
samples/Terra/cunion2.t
Normal file
@@ -0,0 +1,35 @@
|
||||
local C = terralib.includecstring [[
|
||||
|
||||
union testunion {
|
||||
int idata;
|
||||
float fdata;
|
||||
};
|
||||
|
||||
void setUnionI(union testunion * u){
|
||||
u->idata = 3;
|
||||
}
|
||||
void setUnionF(union testunion * u){
|
||||
u->fdata = 4.f;
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
terra foo() : int
|
||||
var u : C.testunion
|
||||
C.setUnionI(&u)
|
||||
var f = u.idata
|
||||
C.setUnionF(&u)
|
||||
var f2 = u.fdata
|
||||
return f + f2
|
||||
end
|
||||
|
||||
terra foo2()
|
||||
var a : C.testunion
|
||||
a.fdata = -3.0
|
||||
a.idata = a.idata and not (1 << 31)
|
||||
return a.fdata
|
||||
end
|
||||
|
||||
local test = require("test")
|
||||
test.eq(foo(),7)
|
||||
test.eq(foo2(),3)
|
||||
Reference in New Issue
Block a user