tags:

views:

49

answers:

3

I'm trying to save a void* pointer (or any pointer) into a tcl Object so I can retrieve it later. I saw SWIG convert it to a string with some encoding and later decode it. But in order to make it more efficient, I want to directly get the pointer in and out of the tcl obj. Something like a Tcl_GetPointerFromObj(). Is there anyway to do it? Do I need to dig into the Tcl_Obj structure and do some dirty work?

A: 

You could use the Tcl API: Tcl_GetWideIntFromObj(), though I think storing pointers in Tcl is the first step toward madness....

Trey Jackson
To use a big int seems too dangerous, I won't risk it... I want to have both flexibility and speed, so that's the only way.
CyberSnoopy
+3  A: 

I suggest reading this page on the Tcler's Wiki which is on the topic.

Donal Fellows
+1  A: 

You can use Tcl_RegisterObjType to create a new Tcl object type that holds a void pointer. This allows you to extend Tcl so that Tcl_ObjType can be used to store (in your case) void* and to be able to write Tcl_GetPointerfromObj.

Jackson