Manual Pages for UNIX Darwin command on man CrtCommand
MyWebUniversity

Manual Pages for UNIX Darwin command on man CrtCommand

TclCreateCommand(3) Tcl Library Procedures TclCreateCommand(3)

NAME

TclCreateCommand - implement new commands in C

SYNOPSIS

##iinncclluuddee <>

TclCommand TTccllCCrreeaatteeCCoommmmaanndd(interp, cmdName, proc, clientData, deleteProc) AARRGGUUMMEENNTTSS TclInterp *interp (in) Interpreter in which to create new command. |

CONST char *cmd- |

Name (in) | | Name of command. TclCmdProc *proc (in) Implementation of new command: proc will be called whenever cmdName

is invoked as a com-

mand.

ClientData clientData (in) Arbitrary one-word

value to pass to proc and deleteProc. TclCmdDeleteProc *deleteProc (in) Procedure to call before cmdName is

deleted from the inter-

preter; allows for com-

mand-specific cleanup.

If NULL, then no proce-

dure is called before the command is deleted.

DESCRIPTION

TTccllCCrreeaatteeCCoommmmaanndd defines a new command in interp and associates it

with procedure proc such that whenever cmdName is invoked as a Tcl com-

mand (via a call to TTccllEEvvaall) the Tcl interpreter will call proc to process the command. It differs from TTccllCCrreeaatteeOObbjjCCoommmmaanndd in that a

new string-based command is defined; that is, a command procedure is

defined that takes an array of argument strings instead of objects.

The object-based command procedures registered by TTccllCCrreeaatteeOObbjjCCoommmmaanndd

can execute significantly faster than the string-based command proce-

dures defined by TTccllCCrreeaatteeCCoommmmaanndd. This is because they take Tcl

objects as arguments and those objects can retain an internal represen-

tation that can be manipulated more efficiently. Also, Tcl's inter-

preter now uses objects internally. In order to invoke a string-based

command procedure registered by TTccllCCrreeaatteeCCoommmmaanndd, it must generate and fetch a string representation from each argument object before the call and create a new Tcl object to hold the string result returned by the

string-based command procedure. New commands should be defined using

TTccllCCrreeaatteeOObbjjCCoommmmaanndd. We support TTccllCCrreeaatteeCCoommmmaanndd for backwards com-

patibility.

The procedures TTccllDDeelleetteeCCoommmmaanndd, TTccllGGeettCCoommmmaannddIInnffoo, and TTccllSSeettCCoomm-

mmaannddIInnffoo are used in conjunction with TTccllCCrreeaatteeCCoommmmaanndd. TTccllCCrreeaatteeCCoommmmaanndd will delete an existing command cmdName, if one is already associated with the interpreter. It returns a token that may

be used to refer to the command in subsequent calls to TTccllGGeettCCoommmmaanndd-

NNaammee. If cmdName contains any :::: namespace qualifiers, then the com-

mand is added to the specified namespace; otherwise the command is added to the global namespace. If TTccllCCrreeaatteeCCoommmmaanndd 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. Proc should have arguments and result that match the type TTccllCCmmddPPrroocc: typedef int TclCmdProc( ClientData clientData, TclInterp *interp, int argc, CONST char *argv[]); When proc is invoked the clientData and interp parameters will be

copies of the clientData and interp arguments given to TTccllCCrreeaatteeCCoomm-

mmaanndd. Typically, clientData points to an application-specific data

structure that describes what to do when the command procedure is invoked. Argc and argv describe the arguments to the command, argc giving the number of arguments (including the command name) and argv giving the values of the arguments as strings. The argv array will contain argc+1 values; the first argc values point to the argument strings, and the last value is NULL. Note that the argument strings | should not be modified as they may point to constant strings or may be | shared with other parts of the interpreter.

Note that the argument strings are encoded in normalized UTF-8 since |

version 8.1 of Tcl. Proc must return an integer code that is either TTCCLLOOKK, TTCCLLEERRRROORR, TTCCLLRREETTUURRNN, TTCCLLBBRREEAAKK, or TTCCLLCCOONNTTIINNUUEE. See the Tcl overview man page for details on what these codes mean. Most normal commands will only return TTCCLLOOKK or TTCCLLEERRRROORR. In addition, proc must set the interpreter result to point to a string value; in the case of a TTCCLLOOKK return code this gives the result of the command, and in the case of TTCCLLEERRRROORR it gives an error message. The TTccllSSeettRReessuulltt procedure provides an easy interface for setting the return value; for complete details on how the the interpreter result field is managed, see the TTccllIInntteerrpp man

page. Before invoking a command procedure, TTccllEEvvaall sets the inter-

preter result to point to an empty string, so simple commands can return an empty result by doing nothing at all. The contents of the argv array belong to Tcl and are not guaranteed to persist once proc returns: proc should not modify them, nor should it set the interpreter result to point anywhere within the argv values.

Call TTccllSSeettRReessuulltt with status TTCCLLVVOOLLAATTIILLEE if you want to return some-

thing from the argv array. DeleteProc will be invoked when (if) cmdName is deleted. This can occur through a call to TTccllDDeelleetteeCCoommmmaanndd or TTccllDDeelleetteeIInntteerrpp, or by replacing cmdName in another call to TTccllCCrreeaatteeCCoommmmaanndd. 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 TTccllCCmmddDDeelleetteePPrroocc: typedef void TclCmdDeleteProc(ClientData clientData); The clientData argument will be the same as the clientData argument passed to TTccllCCrreeaatteeCCoommmmaanndd.

SEE ALSO

TclCreateObjCommand, TclDeleteCommand, TclGetCommandInfo, TclSet-

CommandInfo, TclGetCommandName, TclSetObjResult KKEEYYWWOORRDDSS bind, command, create, delete, interpreter, namespace Tcl TclCreateCommand(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™