lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

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

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