The procedures Tcl_DeleteCommand, Tcl_GetCommandInfo, and Tcl_SetCommandInfo are used in conjunction with Tcl_CreateObjCommand.
Tcl_CreateObjCommand will delete any command name already associated with the interpreter. It returns a token that may be used to refer to the command in subsequent calls to Tcl_GetCommandName. If Tcl_CreateObjCommand is called for an interpreter that is in the process of being deleted, then it does not create a new command and it returns NULL. ObjProc should have arguments and result that match the type Tcl_ObjCmdProc:
typedef int Tcl_ObjCmdProc( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *objv[]);When proc is invoked the clientData and interp parameters will be copies of the clientData and interp arguments given to Tcl_CreateObjCommand. Typically, clientData points to an application-specific data structure that describes what to do when the command procedure is invoked. Objc and objv describe the arguments to the command, objc giving the number of argument objects (including the command name) and objv giving the values of the arguments. The objv array will contain objc+1 values; the first objc values point to the argument objects, and the last value is NULL.
proc must return an integer code that is either TCL_OK, TCL_ERROR, TCL_RETURN, TCL_BREAK, or TCL_CONTINUE. See the Tcl overview man page for details on what these codes mean. Most normal commands will only return TCL_OK or TCL_ERROR. In addition, if proc needs to return a non-empty result, it must call Tcl_SetObjResult to set the interpreter's result object. In the case of a TCL_OK return code this gives the result of the command, and in the case of TCL_ERROR this gives an error message. Before invoking a command procedure, Tcl_Eval sets interpreter's result object to point to an object representing an empty string, so simple commands can return an empty result by doing nothing at all.
The contents of the objv array belong to Tcl and are not guaranteed to persist once proc returns: proc should not modify them. Call Tcl_SetObjResult if you want to return something from the objv array.
DeleteProc will be invoked when (if) name is deleted. This can occur through a call to Tcl_DeleteCommand or Tcl_DeleteInterp, or by replacing name in another call to Tcl_CreateObjCommand. DeleteProc is invoked before the command is deleted, and gives the application an opportunity to release any structures associated with the command. DeleteProc should have arguments and result that match the type Tcl_CmdDeleteProc:
typedef void Tcl_CmdDeleteProc(ClientData clientData);The clientData argument will be the same as the clientData argument passed to Tcl_CreateObjCommand.
Copyright © 1996 Sun Microsystems, Inc. Copyright © 1995, 1996 Roger E. Critchlow Jr.