From: Roy S. <ro...@mi...> - 2006-10-17 15:25:28
|
Piet wrote: > Hi, all! > > Thanks to Roy Sutton *very much* for the answer, > but things didn't work. > > > Did not work, because (*$1) gets accessed too early. With > "out" or "argout" things won't compile (of course). > I'm struggling here since two weeks(!). Does anyone still > have a clue ? > Piet, I just tried it here and it appears to wrap perfectly. Which version of SWIG are you using? Here is my entire interface file: %module FirstSwigTest %typemap(argout) char** { VALUE arr = rb_ary_new2(1024); int Len = strlen(*$1); for (int i=0; i<Len; i++) { rb_ary_push(arr, (*$1)[i]); } $result = arr; } %typemap(in, numinputs=0) (char ** OUTPUT) (char * tmp) { // Don't know if you need to allocate space or anything, but if so, do it here // If you do, you'll need a typemap to free the space $1 = &tmp } extern "C" bool Go(char** OUTPUT); The resulting output: SWIGINTERN VALUE _wrap_Go(int argc, VALUE *argv, VALUE self) { char **arg1 = (char **) 0 ; bool result; char *tmp1 ; VALUE vresult = Qnil; { // Don't know if you need to allocate space or anything, but if so, do it here // If you do, you'll need a typemap to free the space arg1 = &tmp1 } if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; } result = (bool)Go(arg1); vresult = SWIG_From_bool(static_cast< bool >(result)); ... >snip< Roy |