On Sat, Sep 24, 2022 at 3:51 AM Sean Conner wrote:
-- XXX might want to double check that _ENV ius always the
-- first upvalue. Or cycle through any upvalues, looking
-- for a table that is equal to the current _ENV.
-- ----------------------
debug.setupvalue(modfun,1,newenv)
It is impossible to determine the index of the _ENV upvalue of a function with debug info stripped.
Example:
local env = _ENV
local function f()
if env then
print(env)
end
end
print(debug.getupvalue(f, 1)) --> env table: 0x55ee9bd89c50
print(debug.getupvalue(f, 2)) --> _ENV table: 0x55ee9bd89c50