lua-users home
lua-l archive

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

That is because of the way Lua handles tables.

It only counts to the first nil, and stops.

Since you have 'holes' in your array in the first case (It bumps into the nil), it counts 12.

But with the second case you appended right to the can get the proper count.

If you need to keep a count in this case, you will need to do the tracking yourself with a counter.


Joel Sundquist

On Sat, Sep 14, 2013 at 10:09 PM, Jayanth Acharya <> wrote:
Was mixing the table (as associated arrays) and regular array semantics, and results surprised me a bit.

-- initially declared xyz as an array of length 12
xyz = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'}

xyz[110] = 'N'

xyz[13] = 'M'