[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Isn't load() in 5.2 too naive about _ENV?
- From: Artur Galyamov <artur-pub@...>
- Date: Wed, 05 Oct 2011 19:03:57 +0400
05.10.2011, 14:27, "Luiz Henrique de Figueiredo" <email@example.com>:
>> 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).
> Upvalue names may not be available of debug information has been stripped.
Aww, thanks.. I didn't know about stripping.
So, please correct me, if I am wrong. To properly change environment
of Lua function, that function should in general follow "_ENV is first
upvalue" protocol. This is only guaranteed for newly compiled chunks,
i.e. load() with source string argument, and not for string.dump'ed or
other arbitrary chunks.