lua-users home
lua-l archive

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


> On Mar 12, 2015, at 9:43 PM, Paul K <paul@zerobrane.com> wrote:
> 
> Hi Tim,
> 
> > The compiler clearly knows if it’s emitting a function with _ENV as the first upvalue, since it takes care to ensure it is always the first upvalue in the function. However, this information doesnt seem to make it into the compiled chunk anywhere (that I can see).
> 
> You may try to avoid this problem by serializing a special value instead of _ENV. When you serialize the upvalues, you know if the first one points to the _ENV for the given function, so just store a special table value for it, so that when you deserialize it to setup proper value, you know that this function expects _ENV as the first upvalue, so you can do whatever is appropriate in this case.
> 
> Paul.
> ​


Yes, I know how to represent _ENV in the serialization as a placeholder. The problem is the code DOESN’T actually know if the closure has _ENV or not in the first upvalue. Hard-wiring in this knowledge into the code is very fragile, as even a minor one-line change to a function can change the status of the first upvalue. I’d much prefer a way to determine by inspection if _ENV is in the first upvalue or not.

—Tim