[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua registry, environment, and threads.
- From: Mark Hamburg <mark@...>
- Date: Sat, 9 Jan 2010 09:39:07 -0800
On Jan 9, 2010, at 7:37 AM, David Manura wrote:
> On Sat, Jan 9, 2010 at 6:29 AM, steve donovan wrote:
>> However, (and this is a nasty) there are some tricks you cannot do
>> with debug.setfenv.
>>
>> Consider this implementation of David Manura's 'module environment ~=
>> module table' idea: [package.clean] ....
>
> http://lua-users.org/wiki/ModuleDefinition
>
>> debug.setfenv(3,env) .....
>> ../lua: ./closed.lua:12: 'setfenv' cannot change environment of given object
>
> In 5.1, setfenv can take a stack level number but debug.setfenv can
> not. debug.setfenv can take a userdata but setfenv could not. One is
> not a subset of the other. Now, in 5.1 you can alternately obtain the
> function at a given stack level number like debug.getinfo(3, 'f').func
> and then call setfenv or debug.setenv on it to achieve the same effect
> to setenv with a stack level number. In Lua 5.2.0-work1, this
> functionality is maintained, though in the debug library.
Wow. I'm sure the 5.1 spec said this, but I hadn't appreciated that setfenv with a numeric parameter actually changes the environment of the function at that spot on the stack rather than an environment reference in the activation record.
The fact that debug.setenv can muck with the environment for userdata does not strike me as a good thing if it is to be the replacement for the old setfenv.
Mark
- References:
- Lua registry, environment, and threads., Christian Tellefsen
- Re: Lua registry, environment, and threads., Mark Hamburg
- Re: Lua registry, environment, and threads., Patrick Donnelly
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Enrico Colombini
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Edgar Toernig
- Re: Lua registry, environment, and threads., Mark Hamburg
- Re: Lua registry, environment, and threads., Leo Razoumov
- Re: Lua registry, environment, and threads., steve donovan
- Re: Lua registry, environment, and threads., David Manura