tags:

views:

128

answers:

2

I've read about Lua, it's almost perfect language, but there was critical error. It's one-based indexing. I read also it has a feature to setting value at index 0, but it's not counted table length and string manipulations are still one-based. So the feature is meaningless.

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

A: 

Even if there was a #define TABLE_START_INDEX 1 in the Lua sources (which I don't believe there is) you would pretty much shoot yourself in the leg by changing this. This is due to most libraries using 1-based indexing. Thus any code doing something like the following would break.

for i = 1, #t do ... end

You can of course use iterators or even create helper functions to avoid this.

function get_first(t) return t[1] end

Probably though the actual problem you are trying to solve is harder than changing from 0 to 1-based indexing.

ponzao
Nope. It's not a real problem. Real problem is base language should be the C which is 0-based indexing language. Indexing data interchanging between script and host must be correctly translated. And I have to handle dual indexing system at once always.
Eonil
+1  A: 

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 to great a price to pay for ease of use.

gwell
It seems there's no easy way to override this behavior.
Eonil