blob: 26dc162fdd74b50801067aaf13ca1508bb0833c8 (
plain)
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
|
$debug
function check (object, class)
local v = next(object,nil);
while v ~= nil do
if class[v] = nil then print("unknown field: " .. v)
elseif type(object[v]) ~= class[v].type
then print("wrong type for field " .. v)
end
v = next(object,v);
end
v = next(class,nil);
while v ~= nil do
if object[v] = nil then
if class[v].default ~= nil then
object[v] = class[v].default
else print("field "..v.." not initialized")
end
end
v = next(class,v);
end
end
typetrilha = @{x = @{default = 0, type = "number"},
y = @{default = 0, type = "number"},
name = @{type = "string"}
}
function trilha (t) check(t,typetrilha) end
t1 = @trilha{ x = 4, name = "3"}
a = "na".."me"
|