Posted to tcl by apw at Fri Sep 14 07:37:38 GMT 2007view raw
- I have found a solution to my problems of defering to load Tk until it is needed in itcl-ng.
- What I have done is:
- in itcl-ng I have defined on C-level tcl commands for example:
- Tcl_CreateObjCommand(interp, "::itcl::widget", Itcl_WidgetCmdStart,
- (ClientData)infoPtr, (Tcl_CmdDeleteProc*)NULL);
- /*
- * ------------------------------------------------------------------------
- * Itcl_WidgetCmdStart()
- *
- * that is just a dummy command to load package ItclWidget
- * and then to resend the command and execute it in that package
- * package ItclWidget is renaming the Tcl command!!
- *
- * ------------------------------------------------------------------------
- */
- int
- Itcl_WidgetCmdStart(
- ClientData clientData, /* info for all known objects */
- Tcl_Interp *interp, /* current interpreter */
- int objc, /* number of arguments */
- Tcl_Obj *CONST objv[]) /* argument objects */
- {
- ItclShowArgs(0, "Itcl_WidgetCmdStart", objc, objv);
- const char *res = Tcl_PkgRequire(interp, "ItclWidget", "4.0", 0);
- if (res == NULL) {
- return TCL_ERROR;
- }
- return Tcl_EvalObjv(interp, objc, objv, 0);
- }
- and in the additional package ItclWidget, which is linked agaist Tk lib, I have the following:
- TclRenameCommand(interp, "::itcl::widget", "::itcl::__widget");
- Tcl_CreateObjCommand(interp, "::itcl::widget", Itcl_WidgetCmd,
- (ClientData)infoPtr, (Tcl_CmdDeleteProc*)NULL);
- C-function Itcl_WidgetCmd is doing the real work from that point on, and as the Tcl_EvalObjv command is calling the parser again, now the Itcl_WidgetCmd is called without interaction from the user