[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: a new proposal for environments
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 25 Feb 2010 22:30:13 -0300
> I did exactly what Patrick is suggesting in my Lua dialect back in 2003.
> The initial motivation was to support unloading of modules. Upvalue 0
> held a reference to the library which was inherited via pushcclosure.
> When that reference was collected, the library was unloaded.
>
> Later I modified it to hold a table in that slot (the library reference
> moved into that table) and called that table the "private registry" of
> the module:
>
> #define SOL_IDX_REGISTRY SOL_IDX_STACK(1) /* global registry */
> #define SOL_IDX_PREGISTRY SOL_IDX_UPVALUE(0) /* private registry */
Maybe I did not understand what you are saying, but this private registry
seems to be exactly what I called the "obvious case": what you want is
that all functions being created in a library share a common upvalue
(which happens to be a table). This is exactly the support you get from
luaI_openlib. (Except for functions being created dynamically, which
is not that common and can be done it manually.)
I still fail to see why force all C functions to have a "standard"
uvapule inherited from its creator (except for the main function,
which does not have any upvalues), when that can be done trivially
by the programmer (with some help from auxlib) if/when needed.
-- Roberto