How to wrap a void* pointer into a TCL Object
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 w开发者_开发知识库ith 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?
I suggest reading this page on the Tcler's Wiki which is on the topic.
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.
You could use the Tcl API: Tcl_GetWideIntFromObj()
, though I think storing pointers in Tcl is the first step toward madness....
精彩评论