源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. -- --
  2. -- -- strict.lua
  3. -- -- checks uses of undeclared global variables
  4. -- -- All global variables must be 'declared' through a regular assignment
  5. -- -- (even assigning nil will do) in a main chunk before being used
  6. -- -- anywhere or assigned to inside a function.
  7. -- --
  8. -- -- modified for better compatibility with LuaJIT, see:
  9. -- -- http://www.freelists.org/post/luajit/strictlua-with-stripped-bytecode
  10. -- local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget
  11. -- local mt = getmetatable(_G)
  12. -- if mt == nil then
  13. -- mt = {}
  14. -- setmetatable(_G, mt)
  15. -- end
  16. -- mt.__declared = {}
  17. -- mt.__newindex = function (t, n, v)
  18. -- if not mt.__declared[n] then
  19. -- local info = getinfo(2, "S")
  20. -- if info and info.linedefined > 0 then
  21. -- LogError("assign to undeclared variable '"..n.."'", 2)
  22. -- end
  23. -- mt.__declared[n] = true
  24. -- end
  25. -- rawset(t, n, v)
  26. -- end
  27. -- mt.__index = function (t, n)
  28. -- if not mt.__declared[n] then
  29. -- local info = getinfo(2, "S")
  30. -- if info and info.linedefined > 0 then
  31. -- LogError("variable '"..n.."' is not declared", 2)
  32. -- end
  33. -- end
  34. -- return rawget(t, n)
  35. -- end