Just wondering, does Lua 5.1 or 5.2 provide some mechanism to retrieve the table containing a given variable? E.g. something like:
MyGlobal = 1
Why = 'y'
local x, y = 2, e
assert(gettbl('MyGlobal') == _G)
assert(gettbl('x') == _ENV)
assert(gettbl(Why) == _ENV)
Essentially look up the scope containing a variable, and return a table referring to that scope.
The only way I know in 5.1 is debug.getlocal() which I've found unreliable (tail calls especially are troublesome) and which requires two nested loops.
Sent from my toaster.