lua-users home
lua-l archive

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

David Manura wrote:
> On Thu, Oct 22, 2009 at 10:39 PM, Edgar Toernig wrote:
> > At the moment "o" is a table and you add
> > arbitrary elements to it everything falls apart....
> >    t:add('add',{})
> True, the current Lua design implies that an object implemented as a
> table cannot store arbitrary keys directly inside itself because this
> can interfere with method calls.

A very strong limitation given that tables are the usual datatype to
implement "objects".  Using a proxy table is not only awkward, I see
no reason why it has to be like that.

> That might also be solved with the __getindex/__setindex proposal [1],
> so that "add" would be looked up first in the metatable rather than
> the table itself.

Not really - that proposal is about overriding every index access even
if the key is already in the table.  If you would use that for method
lookup, methods would override table keys and you are still unable to
store arbitrary keys in the object.

You have to differentiate between data lookup ([]) and method lookup (:).
One proposal was using __methindex for the colon instead of __index.

> (I wondered if this behavior could instead be changed with a special
> table __mode rather than adding new metamethods.)

It could but IMHO it shouldn't.  Why being tricky when it can be done

Ciao, ET.

> [1]