⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crtobjcmd.3

📁 linux系统下的音频通信
💻 3
字号:
'\"'\" Copyright (c) 1996-1997 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) @(#) CrtObjCmd.3 1.10 97/07/31 14:10:38'\" .so man.macros.TH Tcl_CreateObjCommand 3 8.0 Tcl "Tcl Library Procedures".BS.SH NAMETcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_SetCommandInfo, Tcl_GetCommandName \- implement new commands in C.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spTcl_Command\fBTcl_CreateObjCommand\fR(\fIinterp, cmdName, proc, clientData, deleteProc\fR).spint\fBTcl_DeleteCommand\fR(\fIinterp, cmdName\fR).spint\fBTcl_DeleteCommandFromToken\fR(\fIinterp, token\fR).spint\fBTcl_GetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR).spint\fBTcl_SetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR).spchar *\fBTcl_GetCommandName\fR(\fIinterp, token\fR).SH ARGUMENTS.AS Tcl_ObjCmdProc *deleteProc in/out.AP Tcl_Interp *interp inInterpreter in which to create a new command or that contains a command..AP char *cmdName inName of command..AP Tcl_ObjCmdProc *proc inImplementation of the new command: \fIproc\fR will be called whenever\fIcmdName\fR is invoked as a command..AP ClientData clientData inArbitrary one-word value to pass to \fIproc\fR and \fIdeleteProc\fR..AP Tcl_CmdDeleteProc *deleteProc inProcedure to call before \fIcmdName\fR is deleted from the interpreter;allows for command-specific cleanup. If NULL, then no procedure iscalled before the command is deleted..AP Tcl_Command token inToken for command, returned by previous call to \fBTcl_CreateObjCommand\fR.The command must not have been deleted..AP Tcl_CmdInfo *infoPtr in/outPointer to structure containing various information about aTcl command..BE.SH DESCRIPTION.PP\fBTcl_CreateObjCommand\fR defines a new command in \fIinterp\fRand associates it with procedure \fIproc\fRsuch that whenever \fIname\fR isinvoked as a Tcl command (e.g., via a call to \fBTcl_EvalObj\fR)the Tcl interpreter will call \fIproc\fR to process the command..PP\fBTcl_CreateObjCommand\fR will delete any command \fIname\fRalready associated with the interpreter.It returns a token that may be used to referto the command in subsequent calls to \fBTcl_GetCommandName\fR.If \fIname\fR contains any \fB::\fR namespace qualifiers,then the command is added to the specified namespace;otherwise the command is added to the global namespace.If \fBTcl_CreateObjCommand\fR is called for an interpreter that is inthe process of being deleted, then it does not create a new commandand it returns NULL.\fIproc\fR should have arguments and result that match the type\fBTcl_ObjCmdProc\fR:.CStypedef int Tcl_ObjCmdProc(	ClientData \fIclientData\fR,	Tcl_Interp *\fIinterp\fR,	int \fIobjc\fR,.VS	Tcl_Obj *CONST \fIobjv\fR[]);.CEWhen \fIproc\fR is invoked, the \fIclientData\fR and \fIinterp\fR parameterswill be copies of the \fIclientData\fR and \fIinterp\fR arguments given to\fBTcl_CreateObjCommand\fR.  Typically, \fIclientData\fR points to anapplication-specific data structure that describes what to do when thecommand procedure is invoked. \fIObjc\fR and \fIobjv\fR describe thearguments to the command, \fIobjc\fR giving the number of argument objects(including the command name) and \fIobjv\fR giving the values of thearguments.  The \fIobjv\fR array will contain \fIobjc\fR values, pointing tothe argument objects.  Unlike \fIargv\fR[\fIargv\fR] used in astring-based command procedure, \fIobjv\fR[\fIobjc\fR] will not contain NULL..PPAdditionally, when \fIproc\fR is invoked, it must not modify the contentsof the \fIobjv\fR array by assigning new pointer values to any element of thearray (for example, \fIobjv\fR[\fB2\fR] = \fBNULL\fR) because this willcause memory to be lost and the runtime stack to be corrupted.  The\fBCONST\fR in the declaration of \fIobjv\fR will cause ANSI-compliantcompilers to report any such attempted assignment as an error.  However,it is acceptable to modify the internal representation of any individualobject argument.  For instance, the user may call\fBTcl_GetIntFromObject\fR on \fIobjv\fR[\fB2\fR] to obtain the integerrepresentation of that object; that call may change the type of the objectthat \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.See the Tcl overview man pagefor details on what these codes mean.  Most normal commands will onlyreturn \fBTCL_OK\fR or \fBTCL_ERROR\fR.In addition, if \fIproc\fR needs to return a non-empty result,it can call \fBTcl_SetObjResult\fR to set the interpreter's result.In the case of a \fBTCL_OK\fR return code this gives the resultof 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 topoint to an object representing an empty string, so simplecommands can return an empty result by doing nothing at all..PPThe contents of the \fIobjv\fR array belong to Tcl and are notguaranteed to persist once \fIproc\fR returns: \fIproc\fR shouldnot modify them.Call \fBTcl_SetObjResult\fR if you wantto return something from the \fIobjv\fR array..PP\fIDeleteProc\fR will be invoked when (if) \fIname\fR is deleted.This can occur through a call to \fBTcl_DeleteCommand\fR,\fBTcl_DeleteCommandFromToken\fR, or \fBTcl_DeleteInterp\fR,or by replacing \fIname\fR in another call to \fBTcl_CreateObjCommand\fR.\fIDeleteProc\fR is invoked before the command is deleted, and gives theapplication an opportunity to release any structures associatedwith the command.  \fIDeleteProc\fR should have arguments andresult that match the type \fBTcl_CmdDeleteProc\fR:.CStypedef void Tcl_CmdDeleteProc(ClientData \fIclientData\fR);.CEThe \fIclientData\fR argument will be the same as the \fIclientData\fRargument 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\fBTcl_DeleteCommand\fR does nothing and returns -1;  otherwiseit returns 0.There are no restrictions on \fIcmdName\fR:  it may refer toa built-in command, an application-specific command, or a Tcl procedure.If \fIname\fR contains any \fB::\fR namespace qualifiers,the command is deleted from the specified namespace..PPGiven a token returned by \fBTcl_CreateObjCommand\fR,\fBTcl_DeleteCommandFromToken\fR deletes the commandfrom a command interpreter.It will delete a command even if that command has been renamed.Once the call completes, attempts to invoke the command in\fIinterp\fR will result in errors.If the command corresponding to \fItoken\fRhas already been deleted from \fIinterp\fR then\fBTcl_DeleteCommand\fR does nothing and returns -1;otherwise it returns 0..PP\fBTcl_GetCommandInfo\fR checks to see whether its \fIcmdName\fR argumentexists as a command in \fIinterp\fR.\fIcmdName\fR may include \fB::\fR namespace qualifiersto identify a command in a particular namespace.If the command is not found, then it returns 0.Otherwise it places information about the commandin the \fBTcl_CmdInfo\fR structurepointed to by \fIinfoPtr\fR and returns 1.A \fBTcl_CmdInfo\fR structure has the following fields:.CStypedef 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;.CEThe \fIisNativeObjectProc\fR field has the value 1if \fBTcl_CreateObjCommand\fR was called to register the command;it is 0 if only \fBTcl_CreateCommand\fR was called.It allows a program to determine whether it is faster tocall \fIobjProc\fR or \fIproc\fR:\fIobjProc\fR is normally fasterif \fIisNativeObjectProc\fR has the value 1.The fields \fIobjProc\fR and \fIobjClientData\fRhave the same meaning as the \fIproc\fR and \fIclientData\fRarguments to \fBTcl_CreateObjCommand\fR;they hold information about the object-based command procedurethat the Tcl interpreter calls to implement the command.The fields \fIproc\fR and \fIclientData\fRhold information about the string-based command procedurethat implements the command.If \fBTcl_CreateCommand\fR was called for this command,this is the procedure passed to it;otherwise, this is a compatibility procedureregistered by \fBTcl_CreateObjCommand\fRthat simply calls the command'sobject-based procedure after converting its string arguments to Tcl objects.The field \fIdeleteData\fR is the ClientData valueto pass to \fIdeleteProc\fR;  it is normally the same as\fIclientData\fR but may be set independently using the\fBTcl_SetCommandInfo\fR procedure.The field \fInamespacePtr\fR holds a pointer to theTcl_Namespace that contains the command..PP\fBTcl_SetCommandInfo\fR is used to modify the procedures andClientData values associated with a command.Its \fIcmdName\fR argument is the name of a command in \fIinterp\fR.\fIcmdName\fR may include \fB::\fR namespace qualifiersto 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 toTcl's internal structure for the command and returns 1.Note that this procedure allows the ClientData for a command'sdeletion procedure to be given a different value than the ClientDatafor 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_GetCommandName\fR provides a mechanism for tracking commandsthat have been renamed.Given a token returned by \fBTcl_CreateObjCommand\fRwhen the command was created, \fBTcl_GetCommandName\fR returns thestring name of the command.  If the command has been renamed since itwas created, then \fBTcl_GetCommandName\fR returns the current name.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 memoryowned by Tcl and is only guaranteed to retain its value as long as thecommand isn't deleted or renamed;  callers should copy the string ifthey need to keep it for a long time..PP.SH "SEE ALSO"Tcl_CreateCommand, Tcl_ResetResult, Tcl_SetObjResult.SH KEYWORDSbind, command, create, delete, namespace, object

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -