lua-users home
lua-l archive

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


2009/11/30 cynthia powers <powcyn@gmail.com>:
> I know arrays start from 1 in lua, and the lua libraries adhere to this
> convention. Is there a way (a macro perhaps) to get it to start from 0
> instead and have the libraries working as usual?
> My setup  is as follows:
> From a c++ world/environment, I have an  antler parser gets which
> "generates" a lua testcase. Each of these tests that I generate are not pure
> lua, they are in a  "c calling lua" and in turn "lua-calling c" environment,
> that gets run on slave processors. When I generate the lua testcases, if I
> could have everything starting from 0, life would gets a lot easier for
> me...

It all depends on the Lua code you want to preserve. If it uses ipairs
only to iterate over arrays, you can override it. However if it uses
#t as mentionned by Mark Feldman you cannot override it for tables.
Even if you did override it (by wrapping tables with proxy userdata),
constructs such as for i=1,#t do end wouldn't iterate over index 0.

Also, you can find patched ("enhanced") Lua versions online with
0-based indexing. This is not Lua but it's close and may fit your
needs.