logo       

How to convert “Swig Tcl Pointer” to “C++ Pointers” ?: msg#00182

programming.swig

Subject: How to convert “Swig Tcl Pointer” to “C++ Pointers” ?

Morteza Saheb Zamani writes:
> Hi,
> I have a C++ program in which several classes are
> defined. Swig converts my C++ classes into .so
(shared
> object) file to be able to load them into Tcl.
>
> Now, I want to have a copy of the objects (created
in
> Tcl) inside C++. Is there any way to convert the
Tcl
> pointer (which is in the form of a string) into
actual
> pointers usable in C++?
>

Yes, you just give it to any SWIG-wrapped function
that takes a pointer.
What more are you looking for?

-- Dave


------------------------------------------------------
Thanks Dave for your reply.
However, we cannot use a swig-wrapped function because
we are not in the Tclsh. in fact, our function, which
receives the swig pointer, is not wrapped by swig and
its interaction with Tcl is done via
Tcl_Interp *interp = Tcl_CreateInterp();

In the following sample code, the problem is with the
four commented lines.

Regards,
Morteza

------------ Beginning of the sample code
#include <stdio.h>
#include <string.h>
#include <chert.h>
#include <tcl.h>

class anyThing {

friend int setChert(ClientData clientData ,Tcl_Interp
*interp ,int objc ,Tcl_Obj *CONST objv[]);

private:
Tcl_Interp *interp;
chert *ch;

public:
anyThing() {
ch = (chert*)0;
interp = Tcl_CreateInterp();
};

void initTcl() {
Tcl_Eval( interp,"load ./libchert.so" );
Tcl_CreateObjCommand(interp,"setChert" ,setChert
,this ,NULL);
};

char *sendCommand(char *cmd , char *arg1) {
Tcl_VarEval( interp , cmd , arg1 , NULL );
char *res = interp->result;
return res;
};

~anyThing() { };
};

int setChert(ClientData clientData ,Tcl_Interp *interp
,int objc ,Tcl_Obj *CONST objv[]) {
printf("Here is the problem : \nSee setChert function
in main.cpp\nfrom line 37 to 41\nThank you so
much\n");

// Here we want to have a function to convert swig
pointer to cpp pointer to access the chert members in
cpp.
// ((anyThing *)clientData)->ch = new
SwigPointerToCppPointer(objv[1]->bytes);

// This line is an example of our goal.
// (((anyThing *)clientData)->ch)->getI();
}

int main(int argc , char *argv[] ) {
char *SwigPointer = "";
char *res = "";
anyThing *any = new anyThing();
any->initTcl();
SwigPointer = any->sendCommand("new_chert ","55");
res = any->sendCommand( "setChert " ,SwigPointer );
return TCL_OK;
}
---------- End of Sample Code

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise