(no title)
strenholme | 4 months ago
https://www.lua.org/pil/14.2.html
That code looks like this in Lua 5.1:
function set(name, val)
rawset(_G, name, val or false)
end
function exists(name)
if rawget(_G, name) then return true end
return false
end
throwError = {__newindex = function(self,name) error("Unknown global " .. name) end,
__index = function(self,name) error("Unknown global " .. name) end
}
setmetatable(_G,throwError)
Then, to use set("a") -- set"a" also works
a = 1
ufo|4 months ago
nmz|4 months ago
That's also solvable using metatables.
Dylan16807|4 months ago