Posted to tcl by apw at Fri Sep 14 07:37:38 GMT 2007view raw

  1. I have found a solution to my problems of defering to load Tk until it is needed in itcl-ng.
  2.  
  3. What I have done is:
  4.  
  5. in itcl-ng I have defined on C-level tcl commands for example:
  6.  
  7. Tcl_CreateObjCommand(interp, "::itcl::widget", Itcl_WidgetCmdStart,
  8. (ClientData)infoPtr, (Tcl_CmdDeleteProc*)NULL);
  9.  
  10. /*
  11. * ------------------------------------------------------------------------
  12. * Itcl_WidgetCmdStart()
  13. *
  14. * that is just a dummy command to load package ItclWidget
  15. * and then to resend the command and execute it in that package
  16. * package ItclWidget is renaming the Tcl command!!
  17. *
  18. * ------------------------------------------------------------------------
  19. */
  20. int
  21. Itcl_WidgetCmdStart(
  22. ClientData clientData, /* info for all known objects */
  23. Tcl_Interp *interp, /* current interpreter */
  24. int objc, /* number of arguments */
  25. Tcl_Obj *CONST objv[]) /* argument objects */
  26. {
  27. ItclShowArgs(0, "Itcl_WidgetCmdStart", objc, objv);
  28. const char *res = Tcl_PkgRequire(interp, "ItclWidget", "4.0", 0);
  29. if (res == NULL) {
  30. return TCL_ERROR;
  31. }
  32. return Tcl_EvalObjv(interp, objc, objv, 0);
  33. }
  34.  
  35. and in the additional package ItclWidget, which is linked agaist Tk lib, I have the following:
  36.  
  37. TclRenameCommand(interp, "::itcl::widget", "::itcl::__widget");
  38.  
  39. Tcl_CreateObjCommand(interp, "::itcl::widget", Itcl_WidgetCmd,
  40. (ClientData)infoPtr, (Tcl_CmdDeleteProc*)NULL);
  41.  
  42.  
  43. 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
  44.  
  45.  
  46.