[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table/array length behavior
- From: Vaughan McAlley <ockegheim@...>
- Date: Thu, 4 Mar 2010 11:05:21 +1100
On 4 March 2010 02:20, M Joonas Pihlaja <jpihlaja@cc.helsinki.fi> wrote:
> The short answer is: because Lua is on crack.
>
> The slightly longer answer is: #t is defined to return an index i of
> such that t[i] is non-nil and t[i+1] is nil, or zero if no such index
> exists.
It’s the price to pay for having cheap (memory and performance) sparse arrays.
t = { [1000000] = 1 }
... is very cheap. Lua tables are key-value pairs at their heart. They
can behave like arrays if you treat them with care (keeping them not
sparse), but C-like arrays are only one data structure of the many
that are possible with tables.
Vaughan