3 ms·
Just use LuaJIT which can handle zero based indexing too.
by Rochus 6y ago
Just use LuaJIT which can handle zero based indexing too.
- wruza 6y agoipairs() will not iterate over 0th element though and # will return one less. If that is not an issue, Lua can "handle" it as well. That is, if I didn't miss a flag in luaconf.h which solves that.
- Rochus 6y agopairs() iterates over all elements. I never use ipairs() but plain numeric for loops. This works well with #. I only use pairs() in exceptional situations when I have to copy a table with unknown contents.
- Benjamin_Dobell 6y agoYou can trivially write your own iterator that starts at 0, and still uses ipairs's (native) iterator internally: function ipairs0(arr) return ipairs(arr), arr, -1 end