CrtCommand.3
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:6k
源码类别:

通讯编程

开发平台:

Visual C++

  1. '"
  2. '" Copyright (c) 1989-1993 The Regents of the University of California.
  3. '" Copyright (c) 1994-1997 Sun Microsystems, Inc.
  4. '"
  5. '" See the file "license.terms" for information on usage and redistribution
  6. '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '" 
  8. '" RCS: @(#) $Id: CrtCommand.3,v 1.5.2.1 2004/07/16 20:46:52 andreas_kupries Exp $
  9. '" 
  10. .so man.macros
  11. .TH Tcl_CreateCommand 3 "" Tcl "Tcl Library Procedures"
  12. .BS
  13. .SH NAME
  14. Tcl_CreateCommand - implement new commands in C
  15. .SH SYNOPSIS
  16. .nf
  17. fB#include <tcl.h>fR
  18. .sp
  19. Tcl_Command
  20. fBTcl_CreateCommandfR(fIinterp, cmdName, proc, clientData, deleteProcfR)
  21. .SH ARGUMENTS
  22. .AS Tcl_CmdDeleteProc **deleteProcPtr
  23. .AP Tcl_Interp *interp in
  24. Interpreter in which to create new command.
  25. .VS 8.4
  26. .AP "CONST char" *cmdName in
  27. .VE
  28. Name of command.
  29. .AP Tcl_CmdProc *proc in
  30. Implementation of new command:  fIprocfR will be called whenever
  31. fIcmdNamefR is invoked as a command.
  32. .AP ClientData clientData in
  33. Arbitrary one-word value to pass to fIprocfR and fIdeleteProcfR.
  34. .AP Tcl_CmdDeleteProc *deleteProc in
  35. Procedure to call before fIcmdNamefR is deleted from the interpreter;
  36. allows for command-specific cleanup.  If NULL, then no procedure is
  37. called before the command is deleted.
  38. .BE
  39. .SH DESCRIPTION
  40. .PP
  41. fBTcl_CreateCommandfR defines a new command in fIinterpfR and associates
  42. it with procedure fIprocfR such that whenever fIcmdNamefR is
  43. invoked as a Tcl command (via a call to fBTcl_EvalfR) the Tcl interpreter
  44. will call fIprocfR to process the command.
  45. It differs from fBTcl_CreateObjCommandfR in that a new string-based
  46. command is defined;
  47. that is, a command procedure is defined that takes an array of
  48. argument strings instead of objects.
  49. The object-based command procedures registered by fBTcl_CreateObjCommandfR
  50. can execute significantly faster than the string-based command procedures
  51. defined by fBTcl_CreateCommandfR.
  52. This is because they take Tcl objects as arguments
  53. and those objects can retain an internal representation that
  54. can be manipulated more efficiently.
  55. Also, Tcl's interpreter now uses objects internally.
  56. In order to invoke a string-based command procedure
  57. registered by fBTcl_CreateCommandfR,
  58. it must generate and fetch a string representation
  59. from each argument object before the call
  60. and create a new Tcl object to hold the string result returned by the
  61. string-based command procedure.
  62. New commands should be defined using fBTcl_CreateObjCommandfR.
  63. We support fBTcl_CreateCommandfR for backwards compatibility.
  64. .PP
  65. The procedures fBTcl_DeleteCommandfR, fBTcl_GetCommandInfofR,
  66. and fBTcl_SetCommandInfofR are used in conjunction with
  67. fBTcl_CreateCommandfR.
  68. .PP
  69. fBTcl_CreateCommandfR will delete an existing command fIcmdNamefR,
  70. if one is already associated with the interpreter.
  71. It returns a token that may be used to refer
  72. to the command in subsequent calls to fBTcl_GetCommandNamefR.
  73. If fIcmdNamefR contains any fB::fR namespace qualifiers,
  74. then the command is added to the specified namespace;
  75. otherwise the command is added to the global namespace.
  76. If fBTcl_CreateCommandfR is called for an interpreter that is in
  77. the process of being deleted, then it does not create a new command
  78. and it returns NULL.
  79. fIProcfR should have arguments and result that match the type
  80. fBTcl_CmdProcfR:
  81. .CS
  82. typedef int Tcl_CmdProc(
  83. ClientData fIclientDatafR,
  84. Tcl_Interp *fIinterpfR,
  85. int fIargcfR,
  86. CONST char *fIargvfR[]);
  87. .CE
  88. When fIprocfR is invoked the fIclientDatafR and fIinterpfR
  89. parameters will be copies of the fIclientDatafR and fIinterpfR
  90. arguments given to fBTcl_CreateCommandfR.
  91. Typically, fIclientDatafR points to an application-specific
  92. data structure that describes what to do when the command procedure
  93. is invoked.  fIArgcfR and fIargvfR describe the arguments to
  94. the command, fIargcfR giving the number of arguments (including
  95. the command name) and fIargvfR giving the values of the arguments
  96. as strings.  The fIargvfR array will contain fIargcfR+1 values;
  97. the first fIargcfR values point to the argument strings, and the
  98. last value is NULL.  
  99. .VS
  100. Note that the argument strings should not be modified as they may
  101. point to constant strings or may be shared with other parts of the
  102. interpreter.
  103. .VE
  104. .PP
  105. .VS
  106. Note that the argument strings are encoded in normalized UTF-8 since
  107. version 8.1 of Tcl.
  108. .VE
  109. .PP
  110. fIProcfR must return an integer code that is either fBTCL_OKfR, fBTCL_ERRORfR,
  111. fBTCL_RETURNfR, fBTCL_BREAKfR, or fBTCL_CONTINUEfR.  See the Tcl overview man page
  112. for details on what these codes mean.  Most normal commands will only
  113. return fBTCL_OKfR or fBTCL_ERRORfR.  In addition, fIprocfR must set
  114. the interpreter result to point to a string value;
  115. in the case of a fBTCL_OKfR return code this gives the result
  116. of the command, and in the case of fBTCL_ERRORfR it gives an error message.
  117. The fBTcl_SetResultfR procedure provides an easy interface for setting
  118. the return value;  for complete details on how the the interpreter result
  119. field is managed, see the fBTcl_InterpfR man page.
  120. Before invoking a command procedure,
  121. fBTcl_EvalfR sets the interpreter result to point to an empty string,
  122. so simple commands can return an empty result by doing nothing at all.
  123. .PP
  124. The contents of the fIargvfR array belong to Tcl and are not
  125. guaranteed to persist once fIprocfR returns:  fIprocfR should
  126. not modify them, nor should it set the interpreter result to point
  127. anywhere within the fIargvfR values.
  128. Call fBTcl_SetResultfR with status fBTCL_VOLATILEfR if you want
  129. to return something from the fIargvfR array.
  130. .PP
  131. fIDeleteProcfR will be invoked when (if) fIcmdNamefR is deleted.
  132. This can occur through a call to fBTcl_DeleteCommandfR or fBTcl_DeleteInterpfR,
  133. or by replacing fIcmdNamefR in another call to fBTcl_CreateCommandfR.
  134. fIDeleteProcfR is invoked before the command is deleted, and gives the
  135. application an opportunity to release any structures associated
  136. with the command.  fIDeleteProcfR should have arguments and
  137. result that match the type fBTcl_CmdDeleteProcfR:
  138. .CS
  139. typedef void Tcl_CmdDeleteProc(ClientData fIclientDatafR);
  140. .CE
  141. The fIclientDatafR argument will be the same as the fIclientDatafR
  142. argument passed to fBTcl_CreateCommandfR.
  143. .PP
  144. .SH "SEE ALSO"
  145. Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_GetCommandInfo, Tcl_SetCommandInfo, Tcl_GetCommandName, Tcl_SetObjResult
  146. .SH KEYWORDS
  147. bind, command, create, delete, interpreter, namespace