returning a structure using SWIG

Paul Simmonds psimmo60 at hotmail.com
Wed Jul 2 10:53:36 EDT 2003


"kj.kjn" <kj.kjn at wanadoo.fr> wrote in message news:<bdu6od$68j$1 at news-reader4.wanadoo.fr>...
> I would like to build a module for the fuction : myReturn find(char ** p1,
> int p2)
> 
> The problem is that I dont know how to specify the myReturn Type using swig.
> 
> myReturn is :
> 
> typedef struct{
>     char * name;
>     char * len[10];
>     time_t time;
> } myReturn
> 
> How to specify a such type in the interface file ?
> 
> Thank you

For the structure, all you need to do is paste this declaration into
the interface file. Job done. Create the structure within the
function, fill it up, return it and (most) everything will work.

To implement the function, though, will take a bit more effort. The
type of the len/p1 item may cause problems as arrays of chars I
believe have to be put together by inline functions within the
interface file, as SWIG doesn't put lists/tuples together
automatically.

However, without a few more details I can't know how easy/complex
that'll be. Could the array of string be passed as an big string with
an array of lengths? This may be a lot easier to parse, and is
understood by SWIG.

HTH,
Paul




More information about the Python-list mailing list