From: Alex Fenton Date: 2008-08-22T01:31:19+09:00 Subject: Re: FILE * friom C to ruby with swig Lyes Amazouz wrote: > I have written a function which prototype is: > > FILE * getContent (void * objetc, char * code); > > This function a FILE * to a temporary file it fill with user data, and copy > in "code" (with strcpy) some string > > I warpedd this function with Swig, but when I call it from a Ruby script, I > have two problems: > > 1- The class of the function output in Ruby is , what is > this class? I looked for it in the net by without results, Hows can I > recover the data from my temporary file with this? is what SWIG returns when it doesn't know how to deal with the type returned by a C function. It's an opaque and useless pointer. You need to deal with FILE* - typically by using a %typemap(out) - in some way. I don't know exactly how to deal with FILE* - there may be a standard SWIG typemap to deal with this, or you might search for examples to convert it to a Ruby File object. > 2- when I call this function from a C program, the variable code will > contain a string value that the function copy to it from an other variable > in internal. and with a C program, the content of the variable code is > updated very well. But when I call the wrapped function from a Ruby script, > the argument code stays empty (empty string "")? How have to give this > argument in such way that it will be modified? Passing in a char* buffer which is modified by a function is a very common idiom in C, but it's un-rubyish. Again, you'll need a %typemap(in) or write a wrapper function. Have a look at the *INOUT standard typemaps in SWIG. Usually the most natural ruby way to deal with this is to use %typemap(in,numinputs=0) and return two VALUEs to ruby, the file object and a new string. alex