[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Isn't load() in 5.2 too naive about _ENV?
- From: Peng Zhicheng <pengzhicheng1986@...>
- Date: Thu, 06 Oct 2011 14:50:45 +0800
于 2011-10-5 23:03, Artur Galyamov 写道:
05.10.2011, 14:27, "Luiz Henrique de Figueiredo"<lhf@tecgraf.puc-rio.br>:
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. -- Artur
Lua 5.2 has changed the semantic of the "global namespace", there is no longer a dedicated fenv table, but the first upvalue instead.
the `_ENV' identifier is just the **DEFAULT** lexical name for the "first upvalue", so it is meaningful only at compile time. when a chunk is compiled,
all access to global names are looked up in the first upvalue, the identifier `_ENV' would just be in the debug data to represent the `name' of
the first upvalue, which could be totally stripped out.
in fact, you may change this in luaconf.h when you config and build Lua 5.2, or even at runtime from C, see LexState.