[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: table insertion [was: Lua 5.1 (work2) now available]
- From: Mark Hamburg <mhamburg@...>
- Date: Thu, 04 Nov 2004 08:21:13 -0800
Actually, if __index handles length, you can use table.length to invoke
code. I do think, however, that it would probably help to give message
sending it's own metatable support so that t:m() would go through
__callmethod (for example) rather than __index. This could reduce the
complexity of __index metamethods. How this works with inheritance, etc. is
a question that would need more consideration.
on 11/4/04 7:30 AM, David Given at firstname.lastname@example.org wrote:
> On Thursday 04 November 2004 15:08, Roberto Ierusalimschy wrote:
>> I have a proposal for a new operator (after all these years): "*t" would
>> return the "size" of table t. With that operator, the insertion of a new
>> element in an array would be written as <<t[*t+1] = v>>. To remove the
>> last element, we would write <<t[*t] = nil>>.
> I quite like this, but I'm not keen on the new operator.
> In a lot of ways, Lua's greatest strength (objects are tables) is also its
> greatest weakness (tables are objects). It means that we can't use OO syntax
> to manipulate tables. We can't use t.length to return the length of the table
> because it conflicts with trying to fetch the 'length' field...
> Currently, using a new operator is probably the best solution, because it
> makes it clear that the operation is not calling a function (which a
> pseudofunction like length(t) would not). But, is there a better way of
> solving the underlying problem? Might it not be worth finally biting the
> bullet and distinguishing between field lookups and method calls?
> (BTW, would this work via a metatable operation? Could you virtualise it?)