[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: table insertion [was: Lua 5.1 (work2) now available]
- From: Asko Kauppi <asko.kauppi@...>
- Date: Thu, 4 Nov 2004 18:25:20 +0200
I think here's a question on 5.2 vs. 6.0.
- The * operator would be a 5.x evolutionary step. Good one, nice to
get rid of [gs]etn!
- The bigger question needs to be addressed separately, and I wouldn't
call for 5.x compatibility there.
4.11.2004 kello 17:30, David Given kirjoitti:
On Thursday 04 November 2004 15:08, Roberto Ierusalimschy wrote:
I have a proposal for a new operator (after all these years): "*t"
return the "size" of table t. With that operator, the insertion of a
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
greatest weakness (tables are objects). It means that we can't use OO
to manipulate tables. We can't use t.length to return the length of
because it conflicts with trying to fetch the 'length' field...
Currently, using a new operator is probably the best solution, because
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
bullet and distinguishing between field lookups and method calls?
(BTW, would this work via a metatable operation? Could you virtualise
+- David Given --McQ-+ (base 10) = (base pi)
| email@example.com | 1 = 1; 2 = 2; 3 = 3
| (firstname.lastname@example.org) | 3.1415926... = 10.0
+- www.cowlark.com --+ 4 = 12.201220211...