-
Notifications
You must be signed in to change notification settings - Fork 32
/
test21.lua
54 lines (44 loc) · 807 Bytes
/
test21.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local ecs = require "ecs"
local w = ecs.world()
w:register {
name = "size",
"x:int",
"y:int",
init = function (s)
local x, y = s:match "(%d+)x(%d+)"
return { x = tonumber(x), y = tonumber(y) }
end,
marshal = function (s)
local x, y = s:match "(%d+)x(%d+)"
return string.pack("ii", x, y)
end,
}
w:register {
name = "id",
type = "int",
-- for tempalte
marshal = function(v)
return tostring(v)
end,
unmarshal = function(s)
local v = tonumber(s)
return v
-- return string.pack("i", v)
end,
demarshal = function(s)
print ("ID = ", s)
end
}
local eid = w:new {
size = "42x24",
id = 100,
}
local t = w:template {
size = "3x4",
id = 42,
}
w:template_instance(w:new(), t)
for v in w:select "size:in id:in" do
print(v.size.x, v.size.y, v.id)
end
w:template_destruct(t)