lua-users home
lua-l archive

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


Leo Razoumov schrieb:
I am quite surprised that the following code crashes Lua-5.1.2 and
Lua-5.1.3 (luajit)

print( table.concat({[1]=1, [2]=2, [4]=4}, '/') )
Sorry for hijacking, but I noticed that

print( table.concat({1, 2, [4]=4}, '/') )


also works fine. Since the Lua Manual (§2.5.7) reads

Finally, fields of the form |exp| are equivalent to |[i] = exp|, where |i| are consecutive numerical integers, starting with 1.

I expected the code to construct a table identical to the one from above. Am I missing something?

Regards,
Andreas


Leo Razoumov schrieb:
I am quite surprised that the following code crashes Lua-5.1.2 and
Lua-5.1.3 (luajit)

print( table.concat({[1]=1, [2]=2, [4]=4}, '/') )

stdin:1: bad argument #1 to 'concat' (table contains non-strings)
stack traceback:
        [C]: in function 'concat'
        stdin:1: in main chunk
        [C]: ?
The table above has a single hole (missing t[3]). Official reference
manual is silent about this case. Is it a bug?

On the other hand, why does the following code works

print( table.concat({[1]=1, [3]=3,  [5]=4}, '/') )
1
The last example also has 2 holes (t[2],t[4]) but it works. Go figure:-)

--Leo--