Perhaps someone who knows will contribute something here. I have just found out about this as a result of a message on [comp.lang.tcl]. I have searched this [wikit] and found some pointers, but there is nothing to say to newcomers: '''Here is a way to call your C and C++ from Tcl.''' The Swig web site is http://www.swig.org/index.html '''JPF''' ---- If you look around in books or places like [Cameron Laird]'s Tcl pages [http://starbase.neosoft.com/~claird/comp.lang.tcl/] you can find a lot of information about integrating Tcl with C. That's all fine and dandy if you're going to write the interface code by hand. But if you want a nice example of how you ''ought'' to write your wrappers to call C or C++ from Tcl, then you can't go wrong looking at the code generated by SWIG. David Beazley did a great job of implementing both the "old fashioned" Tcl 7.x all-string interface and the "new fangled" Tcl 8.x object interface. For example, a short little function like this: double convert ( int *value, char *targetUnits ); Gets wrapped by SWIG with this code for Tcl 8.x: static int _wrap_convert(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { double _result; int * _arg0; char * _arg1; Tcl_Obj * tcl_result; char * rettype; int templength; clientData = clientData; objv = objv; tcl_result = Tcl_GetObjResult(interp); if ((objc < 3) || (objc > 3)) { Tcl_SetStringObj(tcl_result,"Wrong # args. convert value targetUnits ",-1); return TCL_ERROR; } if ((rettype = SWIG_GetPointerObj(interp,objv[1],(void **) &_arg0,"_int_p"))) { Tcl_SetStringObj(tcl_result, "Type error in argument 1 of convert. Expected _int_p, received ", -1); Tcl_AppendToObj(tcl_result, rettype, -1); return TCL_ERROR; } if ((_arg1 = Tcl_GetStringFromObj(objv[2], &templength)) == NULL) return TCL_ERROR; _result = (double )convert(_arg0,_arg1); tcl_result = Tcl_GetObjResult(interp); Tcl_SetDoubleObj(tcl_result,(double) _result); return TCL_OK; } If you're using SWIG 1.1 or earlier, it also supported the 7.x interface model: static int _wrap_convert(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { double _result; int * _arg0; char * _arg1; clientData = clientData; argv = argv; if ((argc < 3) || (argc > 3)) { Tcl_SetResult(interp, "Wrong # args. convert value targetUnits ",TCL_STATIC); return TCL_ERROR; } if (SWIG_GetPtr(argv[1],(void **) &_arg0,"_int_p")) { Tcl_SetResult(interp, "Type error in argument 1 of convert. Expected _int_p, received ", TCL_STATIC); Tcl_AppendResult(interp, argv[1], (char *) NULL); return TCL_ERROR; } _arg1 = argv[2]; _result = (double )convert(_arg0,_arg1); Tcl_PrintDouble(interp,(double) _result, interp->result); return TCL_OK; } ---- The new version SWIG 1.3a5 implements the interface in a different way and no longer supports Tcl 7.x. It also no longer has the excellent automatic documentation package in the older version. What it ''does'' have is an excellent macro facility which makes it much easier to interface complicated template classes. '''JPF'''