lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>
>> do
>>> a={10,20,nil,[3]=30,40}
>>> for k,v in pairs(a) do
>>> print(k,v)
>>> end
>>> end
> 1       10
> 2       20
> 4       40
>
> Hmm we explicitly set entry 3 to thirty where did it go?
> t[3]=30 is written
> 40 is loaded into register 4
> setlist then loads registers 1,2,3 and 4 into the table overwriting
> the explicit entry.
>

>
> A little of topic and a corner case I know, but have I missed/misread
> a part of the manual which specifies this behaviour?
>
I think you have discovered a bug.  §3.4.8 of the manual states clearly,
by way of an example, that a table constructor is equivalent to assignment
of the entries from left to right.

A minimal example would be:

    a={1,[1]=10}; print(a[1]) --> prints 1, but should print 10