type.lua 801 B

1234567891011121314151617181920212223242526272829303132333435
  1. $debug
  2. function check (object, class)
  3. local v = next(object,nil);
  4. while v ~= nil do
  5. if class[v] = nil then print("unknown field: " .. v)
  6. elseif type(object[v]) ~= class[v].type
  7. then print("wrong type for field " .. v)
  8. end
  9. v = next(object,v);
  10. end
  11. v = next(class,nil);
  12. while v ~= nil do
  13. if object[v] = nil then
  14. if class[v].default ~= nil then
  15. object[v] = class[v].default
  16. else print("field "..v.." not initialized")
  17. end
  18. end
  19. v = next(class,v);
  20. end
  21. end
  22. typetrilha = @{x = @{default = 0, type = "number"},
  23. y = @{default = 0, type = "number"},
  24. name = @{type = "string"}
  25. }
  26. function trilha (t) check(t,typetrilha) end
  27. t1 = @trilha{ x = 4, name = "3"}
  28. a = "na".."me"
  29.