Originally Posted by Nibs
[...] the "#" operator doesn't count tables.
|
Yes it does. see for example:
Lua Code:
local tables = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
}
print(#tables) -- prints "3"
As long as the indices start at 1 and are contiguous it will count just fine. But if you have an index missing somewhere in the chain, it will stop counting there. For example:
Lua Code:
local tables = {}
tables[1] = {1, 2, 3}
tables[3] = {4, 5, 6} -- Notice we skipped index 2
tables[4] = {7, 8, 9}
print(#tables) -- prints "1"
Edit: Actually, the behaviour of the "#" operator on a non-contiguous table is
undefined, so you cannot rely on the output if the table doesn't have indices in sequence.