#ifndef TCLTK_H #define TCLTK_H #include #include #include #include "TclTkStr.h" // Initialize the required tcl/tk interpretors. // optional parameters - // envname - the environment variable to check for interface file path // tkname - the name of the tk interpreter (for 'send' commands) // interfacename - file to read at startup time. default to interface.tcl int tcltk_init(char *envname="MYAPP_HOME", char *tkname="myAppTk", char *interfacename="interface.tcl"); // Load a tcl file, printing errors in parsing, look in the envname from init void tcltk_loadFile(char *filename); // Evaluate a tcl command, and print errors if they occur TclTkStr tcltk_eval(std::string); TclTkStr tcltk_eval(char *str); // load the file from the users home directory void tcltk_loadUserPrefFile(char *filename); // Check and issue any pending tcltk events, nonblocking void tcltk_checkEvents(void); // Enable stdin as an input into the tcl interpretor // prompt - (optional) the prompt string to use void tcltk_enableTtyInput(char *prompt="tcltk> "); extern Tcl_Interp *tclInterp; extern "C" { int Example_Init(Tcl_Interp *tclInterp); } // tcltk_swigInit(); // to register swig commands #define tcltk_swigInit(foo) Example_Init(tclInterp) // Define a way to get variables into and out of Tcl // tcltk_setVar(foo) - defines a variable in tcl with the val it has in C // tcltk_getVal(foo) - gets the value of the tcl variable foo // Note that these are both overloaded to handle int/float/char */string // in a nice way, you can ignore type. // // int a=5; // tcltk_setVar(a); // tcltk_eval("incr a"); // int b=tcltk_getVal(a); // string c=tcltk_getVal(a); // cout << a << " " << b << " " << c; // // results in '5 6 6' // #define tcltk_setVar(foo) tcltk_eval(std::string("set ") + #foo + std::string(" \"") + std::string(TclTkStr(foo)) + "\""); #define tcltk_getVal(foo) tcltk_eval(std::string("return $") + #foo) #endif