[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: All values can have metatables (Was: Feature request: userdata slice
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 21 Aug 2015 11:14:45 +0200
2015-08-21 8:43 GMT+02:00 Dirk Laurie <dirk.laurie@gmail.com>:
> Something like this?
>
> 1. An array _METATABLES in the registry.
> 2. The 25 unused bits in the type tag are used to index into it.
> 0 means no metatable.
> 3. Any value can have a metatable.
I thought this should be a fairly straightforward patch. Ha-ha.
First, the table does not belong in the registry, it belongs in
the lua_State. There is a current array of Table *mt for the
basic types which will not be needed any more. In its place
must come a list of all metatables. What is the best type
for this? Simply a TValue like l_registry?
Second, the table should be accessible as a pseudo-index
like the registry is.
Third, when you reuse a metatable, you don't want a new entry
into this table. You could just search through the list whenever
setting a metatable, or you could also keep a lookup table.
luaL_getmetatable simply uses the registry for that. Not sure
that is still OK when the keys are the metatables themselves.
Please disagree with any of the above, especially if coding can
be reduced that way!