Skip to content

Instantly share code, notes, and snippets.

@wolfiestyle
Created May 2, 2012 15:11
Show Gist options
  • Save wolfiestyle/2577329 to your computer and use it in GitHub Desktop.
Save wolfiestyle/2577329 to your computer and use it in GitHub Desktop.
require explicit variable assign before usage on specified table
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