lua-users home
lua-l archive

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

I am having some difficulty understanding what is going on in the code below and was hoping someone could enlighten me.

t = { 'one', nil, 'three' }

print(#t) -- 3
print(table.maxn(t)) -- 3

table.insert(t, 5, 'four')

print(#t) -- 1
print(table.maxn(t)) -- 5

Why does #t change to 1 after the table.insert()?

If I specify a position < 5 to table.insert() then #t is not set to 1 and is the same as table.maxn(t).


Jon Nalley