lua-users home
lua-l archive

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


I don't think it's a bug, it says in the manual:
"Given an array where all elements are strings or numbers".
An array in lua implies a continuous list of non-nil values from index 1 and up.

You get the result you get because in the first case, the length of
the table is 1:
> =#{[1]=1, [3]=3,  [5]=4}
1

so it just concatenates between 1 and 1.
In the second example, the length is 4:
> =#{[1]=1, [2]=2, [4]=4}
4

which explains the crash when trying to get the value at index 3.

On Tue, Jul 1, 2008 at 6:01 AM, Leo Razoumov <slonik.az@gmail.com> wrote:
> On 6/28/08, Petite Abeille <petite.abeille@gmail.com> wrote:
>>
>>  On Jun 29, 2008, at 12:54 AM, Leo Razoumov wrote:
>> > The last example also has 2 holes (t[2],t[4]) but it works.
>>
>>  ipairs "will iterate over the pairs (1,t[1]), (2,t[2]), ···, up to the
>> first integer key absent from the table."
>>
>>  http://www.lua.org/manual/5.1/manual.html#pdf-ipairs
>
> My problem is with "table.concat" and _not_ with ipairs.
> Reading carefully your reply I still cannot figure it out while one
> hole breaks table.concat but two holes work fine.
>
> Finally, nil values are not stored in a table. According to the
> reference manual assigning t[k]=nil clears the t[k] value.
>
>>  "Don't claim that you have found a bug"
>>  -- Eric Steven Raymond, "How To Ask Questions The Smart Way", 2001
>> http://www.catb.org/~esr/faqs/smart-questions.html#id306810
>>
>
> It is either a bug in Lua implementation or a bug in Lua documentation.
>
> --Leo--
>