[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: A loaded binary chunk may have wrong upvalues
- From: 张睿 <zrui16@...>
- Date: Fri, 24 Oct 2014 21:48:38 +0800
In the reference manual, §6.1:
>If the resulting function has upvalues, the first upvalue is set to the value of env, if that parameter is given, or to the value of the global environment. (When you load a main chunk, the resulting function will always have exactly one upvalue, the _ENV variable (see §2.2). However, when you load a binary chunk created from a function (see string.dump), the resulting function can have arbitrary upvalues.)
The last sentence states that load() can be used for binary chunks and they can have arbitrary upvalues. However the implementation does not follow this.
BTW, why do you say this is a limitation of string.dump, instead of load?
P.S. There is an even simpler case for this bug to show up:
local x
local function f()
return x
end
local function g()
return x, y
end
print(load(string.dump(f))())
print(load(string.dump(g))())
The output is the same.
Regards,
zr
-----Original Message-----
From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of Luiz Henrique de Figueiredo
Sent: Friday, October 24, 2014 9:36 PM
To: Lua mailing list
Subject: Re: A loaded binary chunk may have wrong upvalues
This is a limitation of string.dump. It can only be used for "main"
functions, that is, functions that come from a complete chunk. These have their first (and only) upvalue equal to _ENV.