Advertisement
devincpp

self_defined_tcl_command

Sep 19th, 2023 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <tcl.h>
  5.  
  6. extern "C" {
  7. // extern for C++.
  8. int Myimpltcl_Init(Tcl_Interp *Interp);
  9. int Myimpltcl_Unload(Tcl_Interp *Interp);
  10. }
  11.  
  12. int Action_FuncA(int notUsed, Tcl_Interp *interp, int argc, char **argv) {
  13.   if (argc != 3) {
  14.     // check args, same as main function args.
  15.     Tcl_SetResult(interp, "Usage::Action_FuncA arg1 arg2", TCL_VOLATILE);
  16.     return TCL_ERROR;
  17.   }
  18.   printf("argv[1] is %s.\n", argv[1]);
  19.   printf("argv[2] is %s.\n", argv[2]);
  20.   // return string.
  21.   Tcl_SetResult(interp, "return of Action_FuncA", TCL_VOLATILE);
  22.   return TCL_OK;
  23. }
  24.  
  25. int Action_FuncB(int notUsed, Tcl_Interp *interp, int argc, char **argv) {
  26.   if (argc != 2) {
  27.     // check args, same as main function args.
  28.     Tcl_SetResult(interp, "Usage::Action_FuncB arg1", TCL_VOLATILE);
  29.     return TCL_ERROR;
  30.   }
  31.   printf("argv[1] is %s.\n", argv[1]);
  32.   // return string.
  33.   Tcl_SetResult(interp, "return of Action_FuncB", TCL_VOLATILE);
  34.   return TCL_OK;
  35. }
  36.  
  37. int Myimpltcl_Init(Tcl_Interp *Interp) {
  38.   // initialize operation.
  39.   Tcl_CreateCommand(Interp, "Action_FuncA", (Tcl_CmdProc *)Action_FuncA, 0, 0);
  40.   Tcl_CreateCommand(Interp, "Action_FuncB", (Tcl_CmdProc *)Action_FuncB, 0, 0);
  41.   return TCL_OK;
  42. }
  43.  
  44. int Myimpltcl_Unload(Tcl_Interp *Interp, int flags) {
  45.   // destroy operation.
  46.   return TCL_OK;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement