lua-users home
lua-l archive

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


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.

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.  (I wondered if this behavior could instead be
changed with a special table __mode rather than adding new
metamethods.)

[1] http://lua-users.org/lists/lua-l/2004-06/msg00478.html

On Thu, Oct 22, 2009 at 9:29 PM, Geoff Leyland wrote:
> Python's repr doesn't seem to have a format object?

Nope.

>> I once posted, though have since removed, an idea like
>> that on the wiki [3].
> Why did you remove it?

I didn't have a much of an opinion of whether this was a useful
approach, and there was an objection that tostring should not confuse
debugging and serialization.  Unlike your suggestion, this redefined
tostring rather than create a separate metamethod.

> These objects can certainly be 'tostring'ed, but o:__tostring() and
> o.__tostring(o) won't work, they'll just get remembered.

If I understand correctly, your __index could could keys prefixed by "__".