[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Isn't load() in 5.2 too naive about _ENV?
- From: Artur Galyamov <artur-pub@...>
- Date: Wed, 05 Oct 2011 05:36:15 +0400
Why does load(...) in 5.2 make an assumption, that _ENV is *always*
first upvalue? I think it should search for the name "_ENV" instead
(and set nothing, if not found).
------------------------------------------------------------
local upvalue
function test()
return upvalue, global
end
assert(debug.getupvalue(test, 1) == "upvalue")
assert(debug.getupvalue(test, 2) == "_ENV")
local f = load(string.dump(test), nil, nil, "environment")
-- bad thing happened...
print(debug.getupvalue(f, 1)) -- "upvalue", "environment"
print(debug.getupvalue(f, 2)) -- "_ENV", nil
------------------------------------------------------------
-- Artur