From: Jim Freeze Date: 2003-05-06T21:47:58+09:00 Subject: SWIG and Ruby (Was Re: SWIG on Solaris problem) On Tuesday, 6 May 2003 at 0:18:24 +0900, Lyle Johnson wrote: > Jim Freeze wrote: > > OK, this is getting a little trickier. Try this typemap: > > %module example > > %typemap(in) (int *pnArgs, String *pString) (int temp, int i) { > Check_Type($input, T_ARRAY); > temp = RARRAY($input)->len; > $1 = &temp; > $2 = (String *) malloc(sizeof(String)); > for (i = 0; i < $1; i++) { > $2[i] = StringValuePtr(rb_ary_entry($input, i)); > } > } > > %typemap(freearg) String *pString { > free((void *) pString); > } > > void dbInit(int *pnArgs, String *pString); Ok, I have been reading the swig docs and I have a few questions. Other than the code above looking totally greek to me, the swig manual does its best to convince me that I never want to write a typemap. So, why do we have to write a typemap for something so common as char **? Is it because I said that I wanted to call dbInit as: dbInit(n, "some string") instead of dbInit(n, ["some string"]) ? Second question, do I need to learn how to write typemaps? Third question, what is the $1 and $2 in the above typemap. Fourth: Lyle, thanks for all your expert help. -- Jim Freeze ---------- When asked by an anthropologist what the Indians called America before the white men came, an Indian said simply "Ours." -- Vine Deloria, Jr.