lua-users home
lua-l archive

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


Adrien de Croy wrote:
>
> if the class table has a shared metatable, you could add a __classname
> member to it, or even to the table itself.
>
> what I'd like to see is upvalues (or ability to associate data) with the
> light userdata type.
>
> at the moment it can only store a pointer.  It would be great if it
> could store just one more bit of information which could be used to look
> up type information in the host environment.

A full userdata whose payload contains a single pointer is pretty well
precisely that (although it includes both a metatable and an environment
table, that's really not much overhead). So just use full userdata.

The only problem with that is the lack of interning; that is, two
full userdata with the same payload (and metatable/envtable) are
not considered equal, and even if you override __eq, they're not
the same key in a table. But there are well-known workarounds.
(Interned immutable tuples could provide another workaround. :) )