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?


-----Original Message-----
[] 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 for a
C implementation, but it's easy to do it in Lua as well. --lhf