first previous next last contents

Registering the Command

Firstly we need to tell the Tcl interpreter which Tcl command should call which C function. We do this using the Tcl_CreateCommand function. This is typically called within the package initialisation routine. For a package named composition this is the Composition_Init routine.

 * This is called when the library is dynamically linked in with the calling
 * program. Use it to initialise any tables and to register the necessary
 * commands.
int Composition_Init(Tcl_Interp *interp) {
    if (NULL == Tcl_CreateCommand(interp,
                                  (ClientData) NULL,
                                  (Tcl_CmdDeleteProc *) NULL)) {
        return TCL_ERROR;

    return TCL_OK;

In the above example we are saying that the Tcl command 'composition' should call the C function 'tcl_composition'. If we wished to call the C function with a specific argument that is known at the time of this initialisation then we would specify it in the ClientData argument (NULL in this example). The full information on using Tcl_CreateCommand is available in the Tcl manual pages.

first previous next last contents
This page is maintained by staden-package. Last generated on 1 March 2001.