lua-users home
lua-l archive

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


Bilyk, Alex wrote:

In Lua 5.1 w1 script

-- CUT HERE local t = {nil, 1}
print (table.getn(t))
local t = {1, nil}
print (table.getn(t))
local t = {1, 2, nil, 3}
print (table.getn(t))
local t = {1, 2, 3, nil}
print (table.getn(t))
local t = {1, 2, 3, nil, 4}
print (table.getn(t))
local t = {1, 2, 3, 4, nil, 5}
print (table.getn(t))
-- CUT HERE

Output 2
1
4
3
3
6

It seems like nil being at and odd position is somehow has no effect.

From a previous Roberto's post regarding this issue:

"The new getn returns any integer index before a nil. If the array is
properly formatted (no "holes") this will be the last index. If the
array has holes, this index is not well specified."


Just thought i'd remind you...