4 ms·
Nothing prevents you from just using [0].
by naniwaduni 7y ago
Nothing prevents you from just using [0].
- patrec 7y agoI know that luajit is carefully written to make this fast as well, but it's of course nonsense that nothing prevents one from doing that. It breaks `#` for starters: #{[0]=1,2,3} == #{2,3} -- true To be able to use zero-based indices ergonomically, the standard library and so one need adjusting as well.
- pansa2 7y agoYes. I looked into consistently using [0] in the past, overriding `__len` and `__ipairs` etc, but kept running into corner cases that stopped it working robustly. Despite how it may appear, 1-based indexing is quite fundamental to Lua.