lua-users home
lua-l archive

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

On Aug 7, 2008, at 1:12 AM, Mark Gossage wrote:

I have recently had to go back to programming VB.Net and I have been discovering that VB.Net is 0 based where VB6 was 1 based, its a pain I agree.

VB?  Ooo, sorry to hear that!  :-)

I certainly need to add some extra documentation on this matter, but here is my thoughts on the matter. I wanted to keep wrappered vectors & wrappered C-arrays to follow the same convertion that C does(0+), rather than convert to the Lua convention (1+), as the underlying information is still C, not Lua. However if you convert from C-arrays to Lua tables, it makes more sense for them to be numbered as Lua(1+).

With my code, I have a lot of gets and sets which operate on arrays (actually C++ vectors). I would like a way to say within my .i file: "ok, everytime you (lua) access this array, subtract 1 from it before you call the C routine". Basically, I want SWIG to generate these arg2-1's for me.

That said, I can see why someone might want a more natural C way, rather than Lua way, of accessing arrays.

Is there a way to make it an option in SWIG to do the -1's for me for every array access, or do I have write %luacode's for all my routines? That would not be pleasant! :-)

One more thing, is there a way to have SWIG/Lua do type-checking on bound data? Here is what I am doing:

I have code that binds my C++ object to Lua which is as follows:

lua_pushlightuserdata ((lua_State *) _LState, const_cast <void *> (ptr));
    lua_setglobal ((lua_State *) _LState, name);

Within my SWIG .i file, I have:

%typemap (in, checkfn="lua_islightuserdata") BOXLIST_P
   $1 = ($type) lua_touserdata (L, $input);
%typemap (in, checkfn="lua_islightuserdata") BOX_P
   $1 = ($type) lua_touserdata (L, $input);
%apply BOXLIST_P {QList <BoxPlots *> *};
%apply BOX_P {BoxPlots *};

In theory, I can send BOX_P and BOXLIST_P to each others function and cause my program to core. Is there a way I can check that the Lua programmer sent the right type of variable to my wrapped function?

Thanks for all your hard work on the Lua module for SWIG! I really enjoy having a nice alternative to C/C++ when messing with our data!