lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2015-09-30 11:27 GMT+02:00 Soni L. <fakedme@gmail.com>:
> On 30/09/15 03:08 AM, Dirk Laurie wrote:
>> 2015-09-30 2:44 GMT+02:00 Soni L. <fakedme@gmail.com>:
>>
>>> The registry, a table, is SLOW. Can we use upvalues instead?
>>
>> No. The two things are totally different.
<<
>> If your question is actually short for "Are there some things that
>> careless programmers stuff into the registry that would better be
>> done using upvalues?" then the answer would be "Yes, of course".
>>
> In Lua you have 2 options:
>
> 1) Use function upvalues. (for local access)
>
> 2) Use the module table. (for shared access)
>
> There's no such thing as a "registry" in Lua, it only exists in C (and
> debug). I want to bring Lua on par with the C API and vice-versa.

The debug library is very much part of Lua. Things are not in
the debug library because they only exist in C otherwise, they
are there to warn users that they must be used with care.

> I still don't see how the registry is needed, when the Lua side doesn't need
> one.

Current uses for the registry are obtainable by:

    for k,v in pairs(debug.getregistry()) do print(k,type(v)) end

and snooping around.

It contains inter alia the metatables of userdata. These are put
there when a module is loaded. The calling program doesn't
know in advance what modules will be loaded.

The only way you could supply that sort of functionality by an
upvalue is to have a standard upvalue _REGISTRY rather like
_ENV containing (ahem!) a table with the same information that
is in the registry. The Lua designers decided that access to that
table should not be possible without going through the debug
library.