[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luajit: any way to make array initialization zero-based?
- From: Tony Finch <dot@...>
- Date: Thu, 14 Jun 2012 12:02:33 +0100
Chris <coderight@gmail.com> wrote:
>
> It's much more complicated than that. Often it's hard to tell what is
> FFI and what is regular Lua. There is not always a clear separation
> because usually a combination of FFI and Lua types are used all at
> once. I run in to this a lot when managing multiple FFI types in a
> regular Lua table and I often introduce bugs because of it (and I
> supposedly know what I am doing; no hope for a regular user).
>
> Unfortunately there doesn't seem to be a clean solution because even
> changing LuaJIT to use one-based indexing will have problems with
> pointer arithmetic and such.
There are four points where Lua has one-based table indexes:
(1) In the implementation, which is invisible apart from the performance
effects. LuaJIT uses a zero base for the array part of its tables.
(2) In the syntax for array-like initialization of tables. You can use the
following pattern to construct zero-based arrays:
t = { [0] = a, b, c }
(3) The length operator.
(4) In the library. Which is actually lots of points :-)
So if you are willing to wrap or reimplement the bits of the library that
you need, it should be fairly easy to adapt your coding style for
zero-based indexing.
Tony.
--
f.anthony.n.finch <dot@dotat.at> http://dotat.at/
Rockall, Malin: East or northeast 5 or 6, increasing 7 or gale 8, perhaps
severe gale 9 later. Moderate or rough, occasionally very rough later.
Occasional rain. Moderate or good.