[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Question about table.maxn() and # operator
- From: "Jon Nalley" <lists@...>
- Date: Mon, 13 Oct 2008 17:01:06 -0500
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).
Regards,
Jon Nalley