mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-25 18:55:35 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
34
samples/Terra/cunion.t
Normal file
34
samples/Terra/cunion.t
Normal file
@@ -0,0 +1,34 @@
|
||||
local C = terralib.includecstring [[
|
||||
|
||||
union testunion {
|
||||
int idata;
|
||||
float fdata;
|
||||
};
|
||||
|
||||
typedef
|
||||
union {
|
||||
int a;
|
||||
float b;
|
||||
} S;
|
||||
|
||||
void setUnion(union testunion * u, S * s){
|
||||
u->idata = 3;
|
||||
}
|
||||
int getUnionInt(union testunion * u){
|
||||
return u->idata;
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
terra foo() : int
|
||||
var u : C.testunion
|
||||
C.setUnion(&u,nil)
|
||||
var s : C.S
|
||||
return C.getUnionInt(&u)
|
||||
end
|
||||
|
||||
|
||||
terralib.tree.printraw(C.S)
|
||||
|
||||
local test = require("test")
|
||||
test.eq(foo(),3)
|
||||
Reference in New Issue
Block a user