OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tcl/] [doc/] [CrtCommand.3] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
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.1.1.1 2002-01-16 10:25:23 markom 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 \fR
18
.sp
19
Tcl_Command
20
\fBTcl_CreateCommand\fR(\fIinterp, cmdName, proc, clientData, deleteProc\fR)
21
.SH ARGUMENTS
22
.AS Tcl_CmdDeleteProc **deleteProcPtr
23
.AP Tcl_Interp *interp in
24
Interpreter in which to create new command.
25
.AP char *cmdName in
26
Name of command.
27
.AP Tcl_CmdProc *proc in
28
Implementation of new command:  \fIproc\fR will be called whenever
29
\fIcmdName\fR is invoked as a command.
30
.AP ClientData clientData in
31
Arbitrary one-word value to pass to \fIproc\fR and \fIdeleteProc\fR.
32
.AP Tcl_CmdDeleteProc *deleteProc in
33
Procedure to call before \fIcmdName\fR is deleted from the interpreter;
34
allows for command-specific cleanup.  If NULL, then no procedure is
35
called before the command is deleted.
36
.BE
37
 
38
.SH DESCRIPTION
39
.PP
40
\fBTcl_CreateCommand\fR defines a new command in \fIinterp\fR and associates
41
it with procedure \fIproc\fR such that whenever \fIcmdName\fR is
42
invoked as a Tcl command (via a call to \fBTcl_Eval\fR) the Tcl interpreter
43
will call \fIproc\fR to process the command.
44
It differs from \fBTcl_CreateObjCommand\fR in that a new string-based
45
command is defined;
46
that is, a command procedure is defined that takes an array of
47
argument strings instead of objects.
48
The object-based command procedures registered by \fBTcl_CreateObjCommand\fR
49
can execute significantly faster than the string-based command procedures
50
defined by \fBTcl_CreateCommand\fR.
51
This is because they take Tcl objects as arguments
52
and those objects can retain an internal representation that
53
can be manipulated more efficiently.
54
Also, Tcl's interpreter now uses objects internally.
55
In order to invoke a string-based command procedure
56
registered by \fBTcl_CreateCommand\fR,
57
it must generate and fetch a string representation
58
from each argument object before the call
59
and create a new Tcl object to hold the string result returned by the
60
string-based command procedure.
61
New commands should be defined using \fBTcl_CreateObjCommand\fR.
62
We support \fBTcl_CreateCommand\fR for backwards compatibility.
63
.PP
64
The procedures \fBTcl_DeleteCommand\fR, \fBTcl_GetCommandInfo\fR,
65
and \fBTcl_SetCommandInfo\fR are used in conjunction with
66
\fBTcl_CreateCommand\fR.
67
.PP
68
\fBTcl_CreateCommand\fR will delete an existing command \fIcmdName\fR,
69
if one is already associated with the interpreter.
70
It returns a token that may be used to refer
71
to the command in subsequent calls to \fBTcl_GetCommandName\fR.
72
If \fIcmdName\fR contains any \fB::\fR namespace qualifiers,
73
then the command is added to the specified namespace;
74
otherwise the command is added to the global namespace.
75
If \fBTcl_CreateCommand\fR is called for an interpreter that is in
76
the process of being deleted, then it does not create a new command
77
and it returns NULL.
78
\fIProc\fR should have arguments and result that match the type
79
\fBTcl_CmdProc\fR:
80
.CS
81
typedef int Tcl_CmdProc(
82
        ClientData \fIclientData\fR,
83
        Tcl_Interp *\fIinterp\fR,
84
        int \fIargc\fR,
85
        char *\fIargv\fR[]);
86
.CE
87
When \fIproc\fR is invoked the \fIclientData\fR and \fIinterp\fR
88
parameters will be copies of the \fIclientData\fR and \fIinterp\fR
89
arguments given to \fBTcl_CreateCommand\fR.
90
Typically, \fIclientData\fR points to an application-specific
91
data structure that describes what to do when the command procedure
92
is invoked.  \fIArgc\fR and \fIargv\fR describe the arguments to
93
the command, \fIargc\fR giving the number of arguments (including
94
the command name) and \fIargv\fR giving the values of the arguments
95
as strings.  The \fIargv\fR array will contain \fIargc\fR+1 values;
96
the first \fIargc\fR values point to the argument strings, and the
97
last value is NULL.
98
.VS
99
Note that the argument strings should not be modified as they may
100
point to constant strings or may be shared with other parts of the
101
interpreter.
102
.VE
103
.PP
104
\fIProc\fR must return an integer code that is either \fBTCL_OK\fR, \fBTCL_ERROR\fR,
105
\fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR.  See the Tcl overview man page
106
for details on what these codes mean.  Most normal commands will only
107
return \fBTCL_OK\fR or \fBTCL_ERROR\fR.  In addition, \fIproc\fR must set
108
the interpreter result to point to a string value;
109
in the case of a \fBTCL_OK\fR return code this gives the result
110
of the command, and in the case of \fBTCL_ERROR\fR it gives an error message.
111
The \fBTcl_SetResult\fR procedure provides an easy interface for setting
112
the return value;  for complete details on how the the interpreter result
113
field is managed, see the \fBTcl_Interp\fR man page.
114
Before invoking a command procedure,
115
\fBTcl_Eval\fR sets the interpreter result to point to an empty string,
116
so simple commands can return an empty result by doing nothing at all.
117
.PP
118
The contents of the \fIargv\fR array belong to Tcl and are not
119
guaranteed to persist once \fIproc\fR returns:  \fIproc\fR should
120
not modify them, nor should it set the interpreter result to point
121
anywhere within the \fIargv\fR values.
122
Call \fBTcl_SetResult\fR with status \fBTCL_VOLATILE\fR if you want
123
to return something from the \fIargv\fR array.
124
.PP
125
\fIDeleteProc\fR will be invoked when (if) \fIcmdName\fR is deleted.
126
This can occur through a call to \fBTcl_DeleteCommand\fR or \fBTcl_DeleteInterp\fR,
127
or by replacing \fIcmdName\fR in another call to \fBTcl_CreateCommand\fR.
128
\fIDeleteProc\fR is invoked before the command is deleted, and gives the
129
application an opportunity to release any structures associated
130
with the command.  \fIDeleteProc\fR should have arguments and
131
result that match the type \fBTcl_CmdDeleteProc\fR:
132
.CS
133
typedef void Tcl_CmdDeleteProc(ClientData \fIclientData\fR);
134
.CE
135
The \fIclientData\fR argument will be the same as the \fIclientData\fR
136
argument passed to \fBTcl_CreateCommand\fR.
137
.PP
138
 
139
.SH "SEE ALSO"
140
Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_GetCommandInfo, Tcl_SetCommandInfo, Tcl_GetCommandName, Tcl_SetObjResult
141
 
142
.SH KEYWORDS
143
bind, command, create, delete, interpreter, namespace

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.