lua-users home
lua-l archive

A loaded binary chunk may have wrong upvalues

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


Here is the lua program to reproduce this:
local function f()
 local x
 return function() return x end
end
local function g()
 local x
 return function() return x, y end
end
print(load(string.dump(f()))())
print(load(string.dump(g()))())
Both f and g return a lua closure with one upvalue (x).
However, lua 5.2 gives the following output on my machine:
table: 0x6000109c0
lua: env.lua:10: attempt to index a nil value (upvalue '_ENV')
stack traceback:
 env.lua:10: in function <env.lua:10>
 env.lua:14: in main chunk
 [C]: in ?
The table printed in the first line is actually _ENV, and not x.
The second print() throws an error, indicating that _ENV was set to nil.
I don't think either is the expected output, therefore I believe that this is a bug of lua implementation.
Lua 5.2 has this bug, and it is not fixed in 5.3 alpha/beta. I didn't test it with other versions.
Regards,
zr

AltStyle によって変換されたページ (->オリジナル) /