diff options
Diffstat (limited to 'doc/CrtObjCmd.3')
| -rw-r--r-- | doc/CrtObjCmd.3 | 129 |
1 files changed, 85 insertions, 44 deletions
diff --git a/doc/CrtObjCmd.3 b/doc/CrtObjCmd.3 index 756b970..e94c8cd 100644 --- a/doc/CrtObjCmd.3 +++ b/doc/CrtObjCmd.3 @@ -4,13 +4,11 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: CrtObjCmd.3,v 1.3 1999/04/16 00:46:30 stanton Exp $ -'\" -.so man.macros .TH Tcl_CreateObjCommand 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros .BS .SH NAME -Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_SetCommandInfo, Tcl_GetCommandName \- implement new commands in C +Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_GetCommandInfoFromToken, Tcl_SetCommandInfo, Tcl_SetCommandInfoFromToken, Tcl_GetCommandName, Tcl_GetCommandFullName, Tcl_GetCommandFromObj \- implement new commands in C .SH SYNOPSIS .nf \fB#include <tcl.h>\fR @@ -30,10 +28,22 @@ int int \fBTcl_SetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR) .sp -char * +int +\fBTcl_GetCommandInfoFromToken\fR(\fItoken, infoPtr\fR) +.sp +int +\fBTcl_SetCommandInfoFromToken\fR(\fItoken, infoPtr\fR) +.sp +const char * \fBTcl_GetCommandName\fR(\fIinterp, token\fR) +.sp +void +\fBTcl_GetCommandFullName\fR(\fIinterp, token, objPtr\fR) +.sp +Tcl_Command +\fBTcl_GetCommandFromObj\fR(\fIinterp, objPtr\fR) .SH ARGUMENTS -.AS Tcl_ObjCmdProc *deleteProc in/out +.AS Tcl_CmdDeleteProc *deleteProc in/out .AP Tcl_Interp *interp in Interpreter in which to create a new command or that contains a command. .AP char *cmdName in @@ -53,13 +63,15 @@ The command must not have been deleted. .AP Tcl_CmdInfo *infoPtr in/out Pointer to structure containing various information about a Tcl command. +.AP Tcl_Obj *objPtr in +Value containing the name of a Tcl command. .BE .SH DESCRIPTION .PP \fBTcl_CreateObjCommand\fR defines a new command in \fIinterp\fR and associates it with procedure \fIproc\fR such that whenever \fIname\fR is -invoked as a Tcl command (e.g., via a call to \fBTcl_EvalObj\fR) +invoked as a Tcl command (e.g., via a call to \fBTcl_EvalObjEx\fR) the Tcl interpreter will call \fIproc\fR to process the command. .PP \fBTcl_CreateObjCommand\fR deletes any existing command @@ -76,38 +88,38 @@ the process of being deleted, then it does not create a new command and it returns NULL. \fIproc\fR should have arguments and result that match the type \fBTcl_ObjCmdProc\fR: +.PP .CS -typedef int Tcl_ObjCmdProc( - ClientData \fIclientData\fR, - Tcl_Interp *\fIinterp\fR, - int \fIobjc\fR, -.VS - Tcl_Obj *CONST \fIobjv\fR[]); +typedef int \fBTcl_ObjCmdProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + int \fIobjc\fR, + Tcl_Obj *const \fIobjv\fR[]); .CE +.PP When \fIproc\fR is invoked, the \fIclientData\fR and \fIinterp\fR parameters will be copies of the \fIclientData\fR and \fIinterp\fR arguments given to \fBTcl_CreateObjCommand\fR. Typically, \fIclientData\fR points to an application-specific data structure that describes what to do when the command procedure is invoked. \fIObjc\fR and \fIobjv\fR describe the -arguments to the command, \fIobjc\fR giving the number of argument objects +arguments to the command, \fIobjc\fR giving the number of argument values (including the command name) and \fIobjv\fR giving the values of the arguments. The \fIobjv\fR array will contain \fIobjc\fR values, pointing to -the argument objects. Unlike \fIargv\fR[\fIargv\fR] used in a +the argument values. Unlike \fIargv\fR[\fIargv\fR] used in a string-based command procedure, \fIobjv\fR[\fIobjc\fR] will not contain NULL. .PP Additionally, when \fIproc\fR is invoked, it must not modify the contents of the \fIobjv\fR array by assigning new pointer values to any element of the array (for example, \fIobjv\fR[\fB2\fR] = \fBNULL\fR) because this will cause memory to be lost and the runtime stack to be corrupted. The -\fBCONST\fR in the declaration of \fIobjv\fR will cause ANSI-compliant +\fBconst\fR in the declaration of \fIobjv\fR will cause ANSI-compliant compilers to report any such attempted assignment as an error. However, it is acceptable to modify the internal representation of any individual -object argument. For instance, the user may call +value argument. For instance, the user may call \fBTcl_GetIntFromObj\fR on \fIobjv\fR[\fB2\fR] to obtain the integer -representation of that object; that call may change the type of the object +representation of that value; that call may change the type of the value that \fIobjv\fR[\fB2\fR] points at, but will not change where \fIobjv\fR[\fB2\fR] points. -.VE .PP \fIproc\fR must return an integer code that is either \fBTCL_OK\fR, \fBTCL_ERROR\fR, \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR. @@ -120,8 +132,8 @@ In the case of a \fBTCL_OK\fR return code this gives the result of the command, and in the case of \fBTCL_ERROR\fR this gives an error message. Before invoking a command procedure, -\fBTcl_EvalObj\fR sets interpreter's result to -point to an object representing an empty string, so simple +\fBTcl_EvalObjEx\fR sets interpreter's result to +point to a value representing an empty string, so simple commands can return an empty result by doing nothing at all. .PP The contents of the \fIobjv\fR array belong to Tcl and are not @@ -149,16 +161,19 @@ or by replacing \fIname\fR in another call to \fBTcl_CreateObjCommand\fR. application an opportunity to release any structures associated with the command. \fIDeleteProc\fR should have arguments and result that match the type \fBTcl_CmdDeleteProc\fR: +.PP .CS -typedef void Tcl_CmdDeleteProc(ClientData \fIclientData\fR); +typedef void \fBTcl_CmdDeleteProc\fR( + ClientData \fIclientData\fR); .CE +.PP The \fIclientData\fR argument will be the same as the \fIclientData\fR argument passed to \fBTcl_CreateObjCommand\fR. .PP \fBTcl_DeleteCommand\fR deletes a command from a command interpreter. Once the call completes, attempts to invoke \fIcmdName\fR in \fIinterp\fR will result in errors. -If \fIcmdName\fR isn't bound as a command in \fIinterp\fR then +If \fIcmdName\fR is not bound as a command in \fIinterp\fR then \fBTcl_DeleteCommand\fR does nothing and returns -1; otherwise it returns 0. There are no restrictions on \fIcmdName\fR: it may refer to @@ -186,18 +201,20 @@ Otherwise it places information about the command in the \fBTcl_CmdInfo\fR structure pointed to by \fIinfoPtr\fR and returns 1. A \fBTcl_CmdInfo\fR structure has the following fields: +.PP .CS typedef struct Tcl_CmdInfo { - int isNativeObjectProc; - Tcl_ObjCmdProc *objProc; - ClientData objClientData; - Tcl_CmdProc *proc; - ClientData clientData; - Tcl_CmdDeleteProc *deleteProc; - ClientData deleteData; - Tcl_Namespace *namespacePtr; -} Tcl_CmdInfo; + int \fIisNativeObjectProc\fR; + Tcl_ObjCmdProc *\fIobjProc\fR; + ClientData \fIobjClientData\fR; + Tcl_CmdProc *\fIproc\fR; + ClientData \fIclientData\fR; + Tcl_CmdDeleteProc *\fIdeleteProc\fR; + ClientData \fIdeleteData\fR; + Tcl_Namespace *\fInamespacePtr\fR; +} \fBTcl_CmdInfo\fR; .CE +.PP The \fIisNativeObjectProc\fR field has the value 1 if \fBTcl_CreateObjCommand\fR was called to register the command; it is 0 if only \fBTcl_CreateCommand\fR was called. @@ -208,7 +225,7 @@ if \fIisNativeObjectProc\fR has the value 1. The fields \fIobjProc\fR and \fIobjClientData\fR have the same meaning as the \fIproc\fR and \fIclientData\fR arguments to \fBTcl_CreateObjCommand\fR; -they hold information about the object-based command procedure +they hold information about the value-based command procedure that the Tcl interpreter calls to implement the command. The fields \fIproc\fR and \fIclientData\fR hold information about the string-based command procedure @@ -218,7 +235,7 @@ this is the procedure passed to it; otherwise, this is a compatibility procedure registered by \fBTcl_CreateObjCommand\fR that simply calls the command's -object-based procedure after converting its string arguments to Tcl objects. +value-based procedure after converting its string arguments to Tcl values. The field \fIdeleteData\fR is the ClientData value to pass to \fIdeleteProc\fR; it is normally the same as \fIclientData\fR but may be set independently using the @@ -226,6 +243,12 @@ to pass to \fIdeleteProc\fR; it is normally the same as The field \fInamespacePtr\fR holds a pointer to the Tcl_Namespace that contains the command. .PP +\fBTcl_GetCommandInfoFromToken\fR is identical to +\fBTcl_GetCommandInfo\fR except that it uses a command token returned +from \fBTcl_CreateObjCommand\fR in place of the command name. If the +\fItoken\fR parameter is NULL, it returns 0; otherwise, it returns 1 +and fills in the structure designated by \fIinfoPtr\fR. +.PP \fBTcl_SetCommandInfo\fR is used to modify the procedures and ClientData values associated with a command. Its \fIcmdName\fR argument is the name of a command in \fIinterp\fR. @@ -234,11 +257,22 @@ to identify a command in a particular namespace. If this command does not exist then \fBTcl_SetCommandInfo\fR returns 0. Otherwise, it copies the information from \fI*infoPtr\fR to Tcl's internal structure for the command and returns 1. -Note that this procedure allows the ClientData for a command's -deletion procedure to be given a different value than the ClientData -for its command procedure. -Note that \fBTcl_SetCmdInfo\fR will not change a command's namespace; -you must use \fBTcl_RenameCommand\fR to do that. +.PP +\fBTcl_SetCommandInfoFromToken\fR is identical to +\fBTcl_SetCommandInfo\fR except that it takes a command token as +returned by \fBTcl_CreateObjCommand\fR instead of the command name. +If the \fItoken\fR parameter is NULL, it returns 0. Otherwise, it +copies the information from \fI*infoPtr\fR to Tcl's internal structure +for the command and returns 1. +.PP +Note that \fBTcl_SetCommandInfo\fR and +\fBTcl_SetCommandInfoFromToken\fR both allow the ClientData for a +command's deletion procedure to be given a different value than the +ClientData for its command procedure. +.PP +Note that neither \fBTcl_SetCommandInfo\fR nor +\fBTcl_SetCommandInfoFromToken\fR will change a command's namespace. +Use \fBTcl_Eval\fR to call the \fBrename\fR command to do that. .PP \fBTcl_GetCommandName\fR provides a mechanism for tracking commands that have been renamed. @@ -250,12 +284,19 @@ This name does not include any \fB::\fR namespace qualifiers. The command corresponding to \fItoken\fR must not have been deleted. The string returned by \fBTcl_GetCommandName\fR is in dynamic memory owned by Tcl and is only guaranteed to retain its value as long as the -command isn't deleted or renamed; callers should copy the string if +command is not deleted or renamed; callers should copy the string if they need to keep it for a long time. .PP - +\fBTcl_GetCommandFullName\fR produces the fully qualified name +of a command from a command token. +The name, including all namespace prefixes, +is appended to the value specified by \fIobjPtr\fR. +.PP +\fBTcl_GetCommandFromObj\fR returns a token for the command +specified by the name in a \fBTcl_Obj\fR. +The command name is resolved relative to the current namespace. +Returns NULL if the command is not found. .SH "SEE ALSO" -Tcl_CreateCommand, Tcl_ResetResult, Tcl_SetObjResult - +Tcl_CreateCommand(3), Tcl_ResetResult(3), Tcl_SetObjResult(3) .SH KEYWORDS -bind, command, create, delete, namespace, object +bind, command, create, delete, namespace, value |
