lua-users home
lua-l archive

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



On 2 October 2013 20:54, Tim Hill <drtimhill@gmail.com> wrote:
No, I'm going to have to check it's an array first, and then iterate it

Why?
Use a numeric for as has been mentioned already in this thread. You are only interested in the int keys, so why care if there is anything else in the table? It is perfectly valid to have, for example, string entries in a table and for the table to still contain a sequence.

As I have personally mentioned before[1][2], and has now been admitted by a member of the Lua team which I believe is the first time or at least to my knowledge, the problem is not so much with the language itself yet how the length operator causes problems for new users.

--Liam

[1]I understand when it is defined to return the correct value, yet
surely by the number of messages the list sees about this would
indicate there is a problem with "#" from a user perspective. Now you
could say that it merely being undefined is fine, yet the Lua language
IIRC has a primary target audience of none developers.

[2] In that case, problem solved until the next table length thread. :)

[3][4][5]...