[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Enhanced tostring
- From: David Manura <dm.lua@...>
- Date: Fri, 23 Oct 2009 01:02:37 -0400
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....
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 ,
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
On Thu, Oct 22, 2009 at 9:29 PM, Geoff Leyland wrote:
> Python's repr doesn't seem to have a format object?
>> I once posted, though have since removed, an idea like
>> that on the wiki .
> 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 "__".