lua-users home
lua-l archive

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


> > "The order in which the indices are
> > enumerated is not specified, even for numeric indices."
> >
> > ... I just somehow fail to believe this can happen...
> 
> For me (using Lua 5.3.5), the code below shows that this can indeed
> happen. Run it a few times if needed.
> 
> t= { 1, 2, "test", 4, x=5, y= 6}
> for n=1,1000 do t[math.random(10)]=n end
> for k, v in pairs( t) do print( k, v) end

Another example is this:

$ lua -e 't={x=1,y=2,[1]=3,[2]=4,[3]=5}; for k,v in pairs(t) do print(k,v) end'

This also may need a few runs to show the behavior.

-- Roberto