4 ms·
This is effectively how globals are handled in Lua: they are first-class environments, ordinary tables which can be assigned to a function (5.1/LuaJIT) or upval
by samatman 4y ago
This is effectively how globals are handled in Lua: they are first-class environments, ordinary tables which can be assigned to a function (5.1/LuaJIT) or upvalue (5.2+) to resolve globals.
I like it a lot, it's a supplement to lexical scope: like ordinary globals it's a flat namespace 'behind' the locals, unlike many implementations of globals these environments are replaceable and (mostly) fungible.