next up previous contents
Next: tclvar Up: tcl++ Previous: Global Variables

Creating a Tcl command

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:

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.



Russell Standish
Mon Feb 20 17:13:01 EST 1995