[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: length operator [was: table insertion]
- From: Mark Hamburg <mhamburg@...>
- Date: Fri, 05 Nov 2004 10:10:16 -0800
But Lua arrays start indexing at 1.
on 11/5/04 4:19 AM, firstname.lastname@example.org at email@example.com wrote:
> My opinion is that all proposed operators to get the length of a table are too
> cryptic to be used with a language with an intuitive syntax as Lua. A more
> intuitive length operator, at least for me, is |t|. Of course |s| could also
> be used to get the length of a string.
> With this operator, appending a value to a table could be written as
> t[|t|]=value. And t=value could be used as a syntatic sugar for appending
> values, but I also like the t=t..value idea.
> Just to make it clear, by length of a table I mean the index of the last
> non-nil element plus 1, or 0 on an empty table. This value can be stored as
> part of the table structure and updated as needed on the C side:
> print(|t|) -- 0
> t[|t|]='a' -- 'a' stored at index 0
> print(|t|) -- 1
> print(|t|) -- 6