Initializing the Extension

   

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 46.  Writing a Tk Widget in C


The widget is packaged as an extension that you can dynamically load into wish. Example 46-1 shows the Clock_Init procedure. It registers two commands, clock and oclock, which use the string-based and Tcl_Obj interfaces, respectively. It also initializes the stub table, which is described in Chapter 45, and declares a package so that scripts can load the widget with package require.

Example 46-1 The Clock_Init procedure.
 int ClockCmd(ClientData clientData,              Tcl_Interp *interp,              int argc, char *argv[]); int ClockObjCmd(ClientData clientData,              Tcl_Interp *interp,              int objc, Tcl_Obj *CONST objv[]); void ClockObjDelete(ClientData clientData); /*  * Clock_Init is called when the package is loaded.  */ int Clock_Init(Tcl_Interp *interp) {    if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {       return TCL_ERROR;    }    Tcl_CreateCommand(interp, "wclock", ClockCmd,           (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);    Tcl_CreateObjCommand(interp, "oclock", ClockObjCmd,           (ClientData)NULL, ClockObjDelete);    Tcl_PkgProvide(interp, "Tkclock", "1.0");    return TCL_OK; } 

       
    Top
     



    Practical Programming in Tcl and Tk
    Practical Programming in Tcl and Tk (4th Edition)
    ISBN: 0130385603
    EAN: 2147483647
    Year: 1999
    Pages: 478

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net