Ashot
Ashot

Reputation: 10959

TCL C API, printing Tcl object

I need simple C/C++ program which creates a Tcl_Obj, set some value to it and prints that value. I need to see how it can be done using C API. Here is what I have done so far.

#include <tcl.h>

int main() {
    Tcl_Interp *interp = Tcl_CreateInterp(); 

    Tcl_Obj* tclObj = new Tcl_NewObj();

    // setting tclObj some value
    // printing it using something like this Tcl_PrintVariable(tclObj);

    return 0;
}

Upvotes: 1

Views: 312

Answers (1)

Oleg Olivson
Oleg Olivson

Reputation: 499

/*set value */
Tcl_SetIntObj(tclObj, 3);
/*print value*/
int i;
Tcl_GetIntFromObj(interp, tclObj, &i);
printf("Value: %d\r\n", i);

Also better to check return value of Tcl_GetIntFromObj(). Refer to this page - Tcl reference manual

Upvotes: 2

Related Questions