From: Lyle Johnson Date: 2004-08-19T22:09:10+09:00 Subject: Re: calling a swig generated function On Thu, 19 Aug 2004 09:58:32 +0900, Michael Hale wrote: > I have a library that I wrapped with SWIG. One of the SWIG generated > functions looks like this: I'm guessing that the fifth argument is declared as a pointer to an unsigned long, correct? The problem is that SWIG doesn't know which one of the many interpretations of that to use. In this case, it appears that the NSCalculateGap() function uses that unsigned long pointer argument to return a value (i.e. for output), but as far as SWIG knows you could be passing in a single unsigned long value, or even an array of unsigned longs, as input. > How should I call this function from ruby? You're going to need to use a typemap of some kind to let SWIG know that, in this case, that unsigned long pointer argument is actually an output value. Depending on how you've written your SWIG interface file, you'll want to do something like this: // Include declarations for output typemaps from the SWIG library %include typemaps.i // Apply SWIG's OUTPUT typemap for unsigned long values to the "ulGap" argument %apply unsigned long *OUTPUT { unsigned long ulGap; } // Here's what I would guess the actual function declaration looks like... void NSCalculateGap(int iMode, int iSpeed, unsigned long ulPacketLength, double dValue, unsigned long *ulGap, int iHub, int iSlot, int iPort); Now, when you call this function from Ruby you will only pass in the seven input arguments, and catch the output value as the method result, e.g. ulGap = Smartlib::NSCalculateGap(iMode, iSpeed, ulPacketLength, dValue, hub, slot, port) For more information, see the "Argument Handling" chapter of the SWIG manual: http://www.swig.org/Doc1.3/Arguments.html Hope this helps, Lyle