[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: absence of a __hash metamethod
- From: Asko Kauppi <askok@...>
- Date: Tue, 20 Nov 2007 08:52:05 +0200
If my memory serves me right, this scenario can be (could be) solved
by the Lua authors by a third kind of "middle" userdata, which would
be pointer based (like light userdata is) but still use metatables.
This way, pointers could be given equality metamethods.
It's been a while since I dug in this pit, though, and I didn't think
proposing a third kind would really be worth it.
Colin kirjoitti 19.11.2007 kello 20:33:
On Fri, Nov 16, 2007 at 09:05:48AM +0900, Miles Bader wrote:
Colin <email@example.com> writes:
I would guess that one of the reasons of the missing __hash meta
that it's not that easy to design -- how do you make sure that
meta event is "compatible" with the Lua hash function and the
Not to mention a non-negligible speed hit in a rather critical
Lua! Making table lookups slower makes _everything_ slower.
(As long as its not slower than the workarounds ... for me, the
of creating caches of all userdata objets to reuse the same when
one with the same value is needed does not sound too good because
application typically much more userdata objects are created than
for table lookups.)
It would probably be much more acceptable if user-defined __hash
were only used for tables with some flag turned on (which could be
tested very quickly in the C core), with that flag defaulting to off.
Hm, this, and the suggestion of using the index/newindex
not work for me either because I want the mechanism to work by
however it gave me the following idea:
How about a flag on every userdata object that switches between the
pointer-based hashing for tables, and one that uses the actual
which the address and length is known) i.e. one could use the same
as for strings, and memcmp() for the equality check)?