Search code examples
indexinglua

Can I force Lua's table indexing to start from zero?


I have an issue with Lua. It uses one-based indexing. The language has a feature to set value at index 0, but the value won't be counted as a part of table length, and string manipulations are still one-based. Therefore, I think the feature is something special rather than about indexing.

I don't want a flame about one-based or zero based. I'm just asking is there a feature to force zero-based indexing.


Solution

  • I think that that Lua already has the feature that you need to make it 0-based. Unfortunately the feature that I refer to is Lua's open source license.

    I was unable to find a patch or fork of Lua that changed the 1-based nature of the language.

    Unfortunately forking Lua to change it to 0-based would also break backwards compatibility. Loss of all the current add-on modules may be too great a price to pay for ease of use.