Skip to content

Instantly share code, notes, and snippets.

@gould
Last active August 29, 2015 14:10
Show Gist options
  • Save gould/ef263bce8ee020df10fd to your computer and use it in GitHub Desktop.
Save gould/ef263bce8ee020df10fd to your computer and use it in GitHub Desktop.
グローバル変数を捕まえよう ref: http://qiita.com/gould/items/7dd68339021d1ded5279
local _KNOWN_GLOBALS = {
_scrollview = true,
imageSheet = true,
LuaLibStore = true,
facebook = true,
socket = true,
store = true,
launchPad = true,
crypto = true,
lfs = true,
--など...
--外部モジュールはたまにGlobalに変数を定義するので、一旦無視をしたい変数をこちらに追加
}
setmetatable(_G, {
__index = function( t, k )
if _KNOWN_GLOBALS[k] then
return
end
print("ERROR", debug.traceback("access of undefined global "..tostring(k), 2))
_KNOWN_GLOBALS[k] = true
end,
__newindex = function( t, k, v )
rawset(t, k, v)
if _KNOWN_GLOBALS[k] then
return
end
print("WARN", debug.traceback("creating new global "..tostring(k).."="..tostring(v), 2))
end
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment