[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua hacking wondering
- From: Dimitris Papavasiliou <jimmyp@...>
- Date: Tue, 22 Jun 2004 22:18:57 +0300
Jamie Webb wrote:
The issue is most likely one of speed. The current behaviour is invoked only
for 'tables misses', which are presumed rare. The behaviour you are
suggesting would require an additional lookup for every table access,
regardless of whether the table actually has this metamethod. The same
problem applies for a __next metamethod, which is one I'd certainly find
useful.
This is the impression I'm under as well, but I was wondering: since
these entries in the metatable (the metamethods that is) are used by the
VM it wouldn't be too ugly to keep a number of flags with each
table/userdata for storing wich (of the "standard") metamethods have
been set in it's metatable. Then every time, say, an index operation
takes place all you have to do is check if the index flag is set (a very
cheap operation) instead of looking up the metatable and indexing it.
The flags can either be kept with the userdata/tables or their
metatables depends on how tables/metatables are handled internally (if
it's fast to get a table/userdata's metatable or if it's fast to get a
metatable's table/userdata). Of course there are bound to be
complications with this (like the fact that a metatable can be bound to
more than one tables/userdatas), that I'm unaware of, as I know almost
nothing about lua internals but I was just wondering if a solution in
that direction might be possible as __settable, __gettable, __next
metamethods would be very nice. Proxy tables seem to make lua API C code
quite complex (you have to keep references to proxy tables, etc.) and
besides it would be more logical to have these metamethods (if they
could be implemented cheaply) than not to.
Dimitris P.