To register a procedure, use the NEWCMD
macro. It takes two
arguments, the first is the name of the Tcl command to be created, the
second is the number of arguments that the Tcl command takes.
NEWCMD
does the following:
GLOBAL_INIT_HOOK
,
which can be set to (for example) initialize any global variables from
Tcl variables.
Here is an example.
#include "tcl++.h" #undef GLOBAL_INIT_HOOK #define GLOBAL_INIT_HOOK init_funny(); static int funny; void init_funny() /* this must be declared before NEWCMD */ { if ( Tcl_GetInt(interp, Tcl_GetVar(interp,"funny",TCL_GLOBAL_ONLY), &funny) !=TCL_OK) error("funny not found"); } NEWCMD(silly_cmd,1) {printf("argv[1]=%s funny=%d\n", argv[1], funny);}This creates a Tcl command that prints out its argument, and the value of the variable
funny
.