[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Metamethod when removing an index from a table?
- From: "Paul Hudson" <phudson@...>
- Date: Tue, 6 Jun 2006 12:33:50 +0100
In my environment, adding a C implementation isn't that easy and I worry
slightly about the overhead of the Lua implementation. On the other hand, I
can check for the metamethod and return to the original pairs etc
implementation pretty quickly...
Is there a definitive list of what I need to overload to make a table with
a proxy holding all the contents work as if it didn't have one?
Ipairs, pairs, __newindex, __index,...
Do table.insert and table.remove honour the __newindex/__index metamethods,
for instance? What about table.getn?
[mailto:email@example.com] On Behalf Of Luiz Henrique de
Sent: 06 June 2006 12:19
To: Lua list
Subject: Re: Metamethod when removing an index from a table?
> I could use a proxy table and catch every access via __newindex, but I
> the problem with that is the main table then doesn't behave right for
> like pairs, because it's empty.
You can redefine pairs to work for proxy tables, say by honoring a __next
metamethod. See http://lua-users.org/wiki/GeneralizedPairsAndIpairs for a
C implementation, but it's easy to do it in Lua as well. --lhf