Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

最近の作業部屋活動履歴

2022-03-25
2019-03-04
2019-03-02
2019-03-01

最近のWikiの更新 (Recent Changes)

2019-03-04
2019-03-02
2019-03-01

Wikiガイド(Guide)

サイドバー (Side Bar)

strict.lua

  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. local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget
  9. local mt = getmetatable(_G)
  10. if mt == nil then
  11. mt = {}
  12. setmetatable(_G, mt)
  13. end
  14. mt.__declared = {}
  15. local function what ()
  16. local d = getinfo(3, "S")
  17. return d and d.what or "C"
  18. end
  19. mt.__newindex = function (t, n, v)
  20. if not mt.__declared[n] then
  21. local w = what()
  22. if w ~= "main" and w ~= "C" then
  23. error("assign to undeclared variable '"..n.."'", 2)
  24. end
  25. mt.__declared[n] = true
  26. end
  27. rawset(t, n, v)
  28. end
  29. mt.__index = function (t, n)
  30. if not mt.__declared[n] and what() ~= "C" then
  31. error("variable '"..n.."' is not declared", 2)
  32. end
  33. return rawget(t, n)
  34. end

Copyright(C)GiderosMobile.com / Japanese translation by. isVowel

利用条件は Gideros のライセンスに従うものとします。