lua-users home
lua-l archive

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


I knew that to be the case, but I was hoping that perhaps there was some amount of a guantee... ah, well.

The good news is: Lua 5.0, 5.1, 5.2, 5.3 and LuaJIT all iterate through arrays in the order 1, 2, 3, ..., N, for both large and small array size N, so I can just quietly let it work and then freak out later when some newer version of Lua changes the behavior. It's not the best... but it'll do for now.

Thanks for letting me know!

On Wed, Aug 17, 2016 at 4:41 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 17.08.2016 um 22:30 schröbte Dirk Laurie:

2016-08-17 19:41 GMT+02:00 ThePhD <jm3689@columbia.edu>:
I have a small question regarding the Lua C API's "lua_next" function when
used on a certain subset of objects: tables that are made like arrays, with
sequential integer keys. Is the order of iteration guaranteed to go from '0'
to 'N' in this case, or am I still subject to jumping around in some
implementation-defined order of traversal?

Nothing is guaranteed, except that if you start from the initial value k=nil
then repeat k,v = next(tbl,k) until not k will visit every key.

`false` is a valid key.

Philipp