4 ms·
ipairs() 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
by wruza 6y ago
ipairs() 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