lua-users home
lua-l archive

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


Interesting idea. 

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?

P.


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Luiz Henrique de
Figueiredo
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
think
> the problem with that is the main table then doesn't behave right for
things
> 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