lua-users home
lua-l archive

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


Hello Sylvain,

To wrap

> typedef unsigned long channel_list_t[CONFIG_MAX_CHANNELS_NUMBER];
> void do_test( channel_list_t * chans);

You cannot (currently) do anything quite so neat. It seems that there might be an issue with SWIG and the array typedef.

I can offer two possible solutions for C code.

1) carray.i
In your interface add the following:
%include <carrays.i>
%array_functions(unsigned long,channel_list_arr)

This will add the following functions:
 *        TYPE *new_NAME(int nelements)
 *        void delete_NAME(TYPE *);
 *        TYPE NAME_getitem(TYPE *, int index);
 *        void NAME_setitem(TYPE *, int index, TYPE value);

So your lua code can be:
aa=new_channel_list(3)
channel_list_setitem(aa,0,1)
channel_list_setitem(aa,1,10)
..
do_test(aa)

2) typemaps.i
You can tell SWIG that what you want it to pass it an array of 3 items.

in your interface add:
%include <typemaps.i>
%apply (unsigned long INPUT[ANY]) {(channel_list_t chans)}

Now you can just call the function with a Lua table
do_test{1,2,3}

Let me know how this works and if you have any problems with it.

PS. I think it would be better to send to the SWIG mailing list for SWI specifc questions.

Regards,
Mark Gossage