strict.lua 428 B

123456789101112131415161718192021222324252627
  1. local strict = {}
  2. strict.defined = {}
  3. -- used to define a global variable
  4. function global(t)
  5. for k, v in pairs(t) do
  6. strict.defined[k] = true
  7. rawset(_G, k, v)
  8. end
  9. end
  10. function strict.__newindex(t, k, v)
  11. error("cannot set undefined variable: " .. k, 2)
  12. end
  13. function strict.__index(t, k)
  14. if not strict.defined[k] then
  15. error("cannot get undefined variable: " .. k, 2)
  16. end
  17. end
  18. setmetatable(_G, strict)