This is because numeric indices are NOT always stored
in the array portion of the table.
Also keep in mind that arrays need to grow and shrink,
the sizes to NEWTABLE are only suggestions for initial
memory allocation.
Also
wouldn't this be faster and behave the same as ipairs: (in
5.1 at least... 5.2 can screw itself for all I care
about... also I didn't test or benchmark it...)
local a,b,c = 1,#t,1
local v = t[a]
while a <= b and v ~= nil do
-- your stuff here
-- use this as if it is "for a,v in ipairs(t) do
<...> end"
a = a + c
v = t[a]
end
No/not for all tables.
#t can be very slow (see the linear
search worst case)
How about:
local a = 1
local v = t[a]
while v ~= nil do
-- your stuff here
-- use this as if it is "for a,v in ipairs(t) do <...>
end"
a = a + 1
v = t[a]
end