From: William S F. <ws...@fu...> - 2011-01-14 19:47:38
|
On 12/01/11 05:03, ran...@gm... wrote: > Hi all, > > I'd like my C function to return an error code to calling Tcl > interpreter. If I were not using Swig, I would do this by 'return > TCL_ERROR' instead of 'return TCL_OK'. > > But with Swig, I see that 'return TCL_OK' is the only possibility > after my function call. > > Is there any way to do what I want? > > I see something like in the generated wrapper function: > > result = (int)myfoo(); > Tcl_SetObjResult(interp,SWIG_From_int(static_cast< int>(result))); > return TCL_OK; //<-- this is the line which I want to have control over Do this with typemaps. If you run SWIG -E, you'll get the preprocessed output, from which you can hunt down the appropriate out typemap, eg you need the 'out' typemap for int for int myfoo(); Here it is: %typemap(out,noblock=1,fragment="SWIG_" "From" "_" {int}) int, const int { Tcl_SetObjResult(interp,SWIG_From_int(static_cast< int >($1))); } Copy this and modify to your hearts contents, eg adding in SWIG_fail, which is a macro to 'goto fail;' which does a return TCL_ERROR. William |