From: Alex Fenton Date: 2006-11-15T18:50:05+09:00 Subject: Re: Ruby <-SWIG-> C arrays Aureliano Buendia wrote: > typedef unsigned long uInt32 > someFunction(uInt32 someArray[]) > > The array is simply some input. Calling the wrapped function in Ruby: > > Wrapper.someFunction([1, 2, 3]) > > produces this error: > > ..in method 'someFunction', argument 1 of type 'uInt32 []' (TypeError) It looks like you require some typemap here to convert a ruby array of integers to a C array of longs. You probably want %typemap(in), which mangles Ruby function/method params to something that the C function can digest. Your %typemap(in) will use the RARRAY($input)->len Ruby C macro to get the length of the incoming ruby array. $input is a placeholder for the ruby parameter being processed. Create a new empty uInt32[]. Then, for each element in the Ruby array use the NUM2LONG macro to convert the Ruby integer to a C long, and add this to your uInt32[]. Lastly, assign the uInt32 to the special variable $1, which is a placeholder for the actual value that will be passed to the C function. SWIG will generate the appropriate wrapper code. You will want to verify the types of the arguments passed in from ruby, using TYPE and T_ARRAY etc macros. Suggest you re-read the following sections of the Ruby/SWIG documentation should be useful: http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn39 http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn47 Sorry I can't give you a complete example, but I'm not a C programmer, just familiar with SWIG. Hopefully this will get you started. alex