3 function check (object
, class
)
4 local v
= next(object
,nil);
6 if class
[v
] == nil then
7 print("unknown field: " .. v
)
8 elseif type(object
[v
]) ~= class
[v
].type then
9 print("wrong type for field " .. v
)
15 if object
[v
] == nil then
16 if class
[v
].default
~= nil then
17 object
[v
] = class
[v
].default
19 print("field "..v
.." not initialized")
26 typeblock
= {x
= {default
= 0, type = "number"},
27 y
= {default
= 0, type = "number"},
28 name
= {type = "string"}
31 function block(t
) check(t
,typeblock
) end
33 block
{ x
= 7, name
= "3"}
34 block
{ x
= "7", name
= "3"}
35 block
{ x
= 7, name
= 3}
37 block
{ x
= 7, name
= "3", bogus
=3.14}