aboutsummaryrefslogtreecommitdiff
path: root/type.lua
diff options
context:
space:
mode:
Diffstat (limited to 'type.lua')
-rw-r--r--type.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/type.lua b/type.lua
new file mode 100644
index 00000000..26dc162f
--- /dev/null
+++ b/type.lua
@@ -0,0 +1,35 @@
1$debug
2
3function check (object, class)
4 local v = next(object,nil);
5 while v ~= nil do
6 if class[v] = nil then print("unknown field: " .. v)
7 elseif type(object[v]) ~= class[v].type
8 then print("wrong type for field " .. v)
9 end
10 v = next(object,v);
11 end
12 v = next(class,nil);
13 while v ~= nil do
14 if object[v] = nil then
15 if class[v].default ~= nil then
16 object[v] = class[v].default
17 else print("field "..v.." not initialized")
18 end
19 end
20 v = next(class,v);
21 end
22end
23
24typetrilha = @{x = @{default = 0, type = "number"},
25 y = @{default = 0, type = "number"},
26 name = @{type = "string"}
27 }
28
29function trilha (t) check(t,typetrilha) end
30
31t1 = @trilha{ x = 4, name = "3"}
32
33a = "na".."me"
34
35 \ No newline at end of file