5 ms·
> work has begun on Lua 5.5 A beta version is now available: https://www.lua.org/work/ https://www.lua.org/work/ The main change from 5.4 seems to be the (op
by pansa2 1y ago
> work has begun on Lua 5.5
A beta version is now available:
https://www.lua.org/work/ https://www.lua.org/work/
The main change from 5.4 seems to be the (optional?) removal of global-by-default, instead requiring declarations for global variables.
- strenholme 1y agoAs it turns out, it’s possible with Lua going back to 5.1 to not allow undeclared global variables: https://www.lua.org/pil/14.2.html 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 1y agoNaturally, the main catch is that this only detects the violation at run-time. It also won't stop you from accidentally overwriting a global variable that already exists.
- nmz 1y ago> It also won't stop you from accidentally overwriting a global variable that already exists. That's also solvable using metatables.
- Dylan16807 1y agoDo the declarations in 5.5 prevent overwriting? That sounds tricky to define and implement.