summaryrefslogtreecommitdiff
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 @@
+$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"
+
+ \ No newline at end of file