[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.2 environments and changing a loaded file environment
- From: Patrick Donnelly <batrick@...>
- Date: Mon, 9 Aug 2010 08:04:58 -0400
On Mon, Aug 9, 2010 at 7:58 AM, Luiz Henrique de Figueiredo
>> I'm trying to decide how best to change the environment of a loaded
>> "script" file such that it can be given a brand new environment and
>> re-executed multiple times without recompiling the script (loadin).
> One solution which has been posted here is to add "_ENV=..." at the top
> of the script before compiling it. Then you can give the environment
> when you call it. This technique only works for scripts that do not
> use args (...).
It would need to be "local _ENV = ..." to avoid the share upvalue
problem though, yes? As stated in the OP, if the script is called
multiple times, all the closures it creates will share the same _ENV
upvalue. So even if you do "_ENV = ...", closures created from
previous calls will get their environments changed.
Still, I would prefer not to modify the script source (through load or
- Patrick Donnelly