lua-users home
lua-l archive

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


I was testing the # operator on a table and got some strange results.
The chunk used was:

t = {10, 20, nil, 40}
print(#t) --> 4 (should not be 2?)
t = {10, nil, nil, 40}
print(#t) --> 4 (should not be 1?)
t = {}; t[1] = 10; t[2] = 20; t[3] = nil; t[4] = 40;
print(#t) --> 4 (should not be 2?)
t = {}; t[1] = 10; t[2] = nil; t[3] = nil; t[4] = 40;
print(#t) --> 1 (OK)

Is this an expected result or a bug?

Regards,

Romeu.