lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

The other strong argument IMHO is when you're biding C/C++ libraries
that use data structures like vectors and other types of 0-based
iterators which when bound as userdata to Lua become confusing because
a coice has to be made...conform to C and use 0-based arguments to its
functions or conform to Lua and use 1-based.  This is for example a
problem with geometric data structures like triangulations where you
have iterators over faces and edges but they are also indexable.  Do
you make 0 the first or 1?


On 10/28/07, Javier Guerra Giraldez <> wrote:
> On Sunday 28 October 2007, David Given wrote:
> > The problem is that when you deal with 1-based arrays, offsets and indices
> > now become *different*. With 0-based arrays, they're the same.
> this is one of the very few concrete arguments one way or the other... and a
> strong one, IMO.
> > The end result is that all my string handling code has to be full of -1s.
> > Ironing out all the off-by-one errors was a pain.
> the problem is that no matter which one you choose, you'll have a lot of
> opportunities for off-by-one errors.  the difference is that starting on 0
> the errors are mostly on 'simple' loops ('noob errors'); and starting on 1
> it's on slightly more complex code (on your case, index additions)
> --
> Javier