3 ms·
You can fix that easily with a metatable. function nilguard(tbl) tbl = tbl or {} local mt = { __index = function(t,k) error("Invalid ke
by sshumaker 15y ago
You can fix that easily with a metatable.
function nilguard(tbl)
tbl = tbl or {}
local mt = {
__index = function(t,k)
error("Invalid key: " .. tostring(tbl) .. "[" .. k .. "]")
end
}
setmetatable(tbl, mt)
return tbl
end
local myObj = nilguard({foo=10})
myObj.crap -- should raise
For undefined global variables, just require("strict")