Created
May 2, 2012 15:11
-
-
Save wolfiestyle/2577329 to your computer and use it in GitHub Desktop.
require explicit variable assign before usage on specified table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setexplicit(table) | |
table = table or _G | |
setmetatable(table, { | |
declared = {}, | |
__newindex = function(t, n, v) | |
getmetatable(t).declared[n] = true | |
rawset(t, n, v) | |
end, | |
__index = function(t, n) | |
if getmetatable(t).declared[n] then | |
return nil | |
else | |
error("undefined variable: "..n, 2) | |
end | |
end | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment