Reputation: 1728
I have structure of Tcl_Interp
for which I don't know what is holding. I tried to print a string value of interp.result
but it's not returning anything. I am using this function:
void debug_state(char *state);
like this:
debug_state(Tcl_GetStringResult(g_game.tcl_interp));
but it isn't returning anything. Is there other way to see string value of tcl_interp
other than char *Tcl_GetStringResult(interp)
Upvotes: 1
Views: 1381
Reputation: 33203
You are not supposed to use the Tcl_Interp* as anything other than an opaque handle to an interpreter. Once upon a time you used interp->result to access the result but this has been deprecated for over a decade. As you have found, Tcl_GetStringResult and often better, Tcl_GetObjResult should be used. In general, in new code you should try to use the Tcl_Obj functions rather than the string functions as this can avoid conversions to and from string types when not necessary.
Your code should be ok, provided debug_state doesn't expect the result value to be valid after your function returns. I would say if you are seeing an empty string that this point then that is what is in your interpreter result. You could check that by setting it to something just before eg: Tcl_SetObjResult(interp, Tcl_NewStringObj("testing, testing...", -1));
. If you then call Tcl_GetStringResult(interp) you should get a char * pointer to a copy of the above string.
Upvotes: 1