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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [doc/] [CrtObjCmd.3] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1996-1997 Sun Microsystems, Inc.
3
'\"
4
'\" See the file "license.terms" for information on usage and redistribution
5
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6
'\"
7
'\" RCS: @(#) $Id: CrtObjCmd.3,v 1.1.1.1 2002-01-16 10:25:23 markom Exp $
8
'\"
9
.so man.macros
10
.TH Tcl_CreateObjCommand 3 8.0 Tcl "Tcl Library Procedures"
11
.BS
12
.SH NAME
13
Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_SetCommandInfo, Tcl_GetCommandName \- implement new commands in C
14
.SH SYNOPSIS
15
.nf
16
\fB#include \fR
17
.sp
18
Tcl_Command
19
\fBTcl_CreateObjCommand\fR(\fIinterp, cmdName, proc, clientData, deleteProc\fR)
20
.sp
21
int
22
\fBTcl_DeleteCommand\fR(\fIinterp, cmdName\fR)
23
.sp
24
int
25
\fBTcl_DeleteCommandFromToken\fR(\fIinterp, token\fR)
26
.sp
27
int
28
\fBTcl_GetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR)
29
.sp
30
int
31
\fBTcl_SetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR)
32
.sp
33
char *
34
\fBTcl_GetCommandName\fR(\fIinterp, token\fR)
35
.SH ARGUMENTS
36
.AS Tcl_ObjCmdProc *deleteProc in/out
37
.AP Tcl_Interp *interp in
38
Interpreter in which to create a new command or that contains a command.
39
.AP char *cmdName in
40
Name of command.
41
.AP Tcl_ObjCmdProc *proc in
42
Implementation of the new command: \fIproc\fR will be called whenever
43
\fIcmdName\fR is invoked as a command.
44
.AP ClientData clientData in
45
Arbitrary one-word value to pass to \fIproc\fR and \fIdeleteProc\fR.
46
.AP Tcl_CmdDeleteProc *deleteProc in
47
Procedure to call before \fIcmdName\fR is deleted from the interpreter;
48
allows for command-specific cleanup. If NULL, then no procedure is
49
called before the command is deleted.
50
.AP Tcl_Command token in
51
Token for command, returned by previous call to \fBTcl_CreateObjCommand\fR.
52
The command must not have been deleted.
53
.AP Tcl_CmdInfo *infoPtr in/out
54
Pointer to structure containing various information about a
55
Tcl command.
56
.BE
57
.SH DESCRIPTION
58
.PP
59
\fBTcl_CreateObjCommand\fR defines a new command in \fIinterp\fR
60
and associates it with procedure \fIproc\fR
61
such that whenever \fIname\fR is
62
invoked as a Tcl command (e.g., via a call to \fBTcl_EvalObj\fR)
63
the Tcl interpreter will call \fIproc\fR to process the command.
64
.PP
65
\fBTcl_CreateObjCommand\fR will delete any command \fIname\fR
66
already associated with the interpreter.
67
It returns a token that may be used to refer
68
to the command in subsequent calls to \fBTcl_GetCommandName\fR.
69
If \fIname\fR contains any \fB::\fR namespace qualifiers,
70
then the command is added to the specified namespace;
71
otherwise the command is added to the global namespace.
72
If \fBTcl_CreateObjCommand\fR is called for an interpreter that is in
73
the process of being deleted, then it does not create a new command
74
and it returns NULL.
75
\fIproc\fR should have arguments and result that match the type
76
\fBTcl_ObjCmdProc\fR:
77
.CS
78
typedef int Tcl_ObjCmdProc(
79
        ClientData \fIclientData\fR,
80
        Tcl_Interp *\fIinterp\fR,
81
        int \fIobjc\fR,
82
.VS
83
        Tcl_Obj *CONST \fIobjv\fR[]);
84
.CE
85
When \fIproc\fR is invoked, the \fIclientData\fR and \fIinterp\fR parameters
86
will be copies of the \fIclientData\fR and \fIinterp\fR arguments given to
87
\fBTcl_CreateObjCommand\fR.  Typically, \fIclientData\fR points to an
88
application-specific data structure that describes what to do when the
89
command procedure is invoked. \fIObjc\fR and \fIobjv\fR describe the
90
arguments to the command, \fIobjc\fR giving the number of argument objects
91
(including the command name) and \fIobjv\fR giving the values of the
92
arguments.  The \fIobjv\fR array will contain \fIobjc\fR values, pointing to
93
the argument objects.  Unlike \fIargv\fR[\fIargv\fR] used in a
94
string-based command procedure, \fIobjv\fR[\fIobjc\fR] will not contain NULL.
95
.PP
96
Additionally, when \fIproc\fR is invoked, it must not modify the contents
97
of the \fIobjv\fR array by assigning new pointer values to any element of the
98
array (for example, \fIobjv\fR[\fB2\fR] = \fBNULL\fR) because this will
99
cause memory to be lost and the runtime stack to be corrupted.  The
100
\fBCONST\fR in the declaration of \fIobjv\fR will cause ANSI-compliant
101
compilers to report any such attempted assignment as an error.  However,
102
it is acceptable to modify the internal representation of any individual
103
object argument.  For instance, the user may call
104
\fBTcl_GetIntFromObject\fR on \fIobjv\fR[\fB2\fR] to obtain the integer
105
representation of that object; that call may change the type of the object
106
that \fIobjv\fR[\fB2\fR] points at, but will not change where
107
\fIobjv\fR[\fB2\fR] points.
108
.VE
109
.PP
110
\fIproc\fR must return an integer code that is either \fBTCL_OK\fR,
111
\fBTCL_ERROR\fR, \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR.
112
See the Tcl overview man page
113
for details on what these codes mean.  Most normal commands will only
114
return \fBTCL_OK\fR or \fBTCL_ERROR\fR.
115
In addition, if \fIproc\fR needs to return a non-empty result,
116
it can call \fBTcl_SetObjResult\fR to set the interpreter's result.
117
In the case of a \fBTCL_OK\fR return code this gives the result
118
of the command,
119
and in the case of \fBTCL_ERROR\fR this gives an error message.
120
Before invoking a command procedure,
121
\fBTcl_EvalObj\fR sets interpreter's result to
122
point to an object representing an empty string, so simple
123
commands can return an empty result by doing nothing at all.
124
.PP
125
The contents of the \fIobjv\fR array belong to Tcl and are not
126
guaranteed to persist once \fIproc\fR returns: \fIproc\fR should
127
not modify them.
128
Call \fBTcl_SetObjResult\fR if you want
129
to return something from the \fIobjv\fR array.
130
.PP
131
\fIDeleteProc\fR will be invoked when (if) \fIname\fR is deleted.
132
This can occur through a call to \fBTcl_DeleteCommand\fR,
133
\fBTcl_DeleteCommandFromToken\fR, or \fBTcl_DeleteInterp\fR,
134
or by replacing \fIname\fR in another call to \fBTcl_CreateObjCommand\fR.
135
\fIDeleteProc\fR is invoked before the command is deleted, and gives the
136
application an opportunity to release any structures associated
137
with the command.  \fIDeleteProc\fR should have arguments and
138
result that match the type \fBTcl_CmdDeleteProc\fR:
139
.CS
140
typedef void Tcl_CmdDeleteProc(ClientData \fIclientData\fR);
141
.CE
142
The \fIclientData\fR argument will be the same as the \fIclientData\fR
143
argument passed to \fBTcl_CreateObjCommand\fR.
144
.PP
145
\fBTcl_DeleteCommand\fR deletes a command from a command interpreter.
146
Once the call completes, attempts to invoke \fIcmdName\fR in
147
\fIinterp\fR will result in errors.
148
If \fIcmdName\fR isn't bound as a command in \fIinterp\fR then
149
\fBTcl_DeleteCommand\fR does nothing and returns -1;  otherwise
150
it returns 0.
151
There are no restrictions on \fIcmdName\fR:  it may refer to
152
a built-in command, an application-specific command, or a Tcl procedure.
153
If \fIname\fR contains any \fB::\fR namespace qualifiers,
154
the command is deleted from the specified namespace.
155
.PP
156
Given a token returned by \fBTcl_CreateObjCommand\fR,
157
\fBTcl_DeleteCommandFromToken\fR deletes the command
158
from a command interpreter.
159
It will delete a command even if that command has been renamed.
160
Once the call completes, attempts to invoke the command in
161
\fIinterp\fR will result in errors.
162
If the command corresponding to \fItoken\fR
163
has already been deleted from \fIinterp\fR then
164
\fBTcl_DeleteCommand\fR does nothing and returns -1;
165
otherwise it returns 0.
166
.PP
167
\fBTcl_GetCommandInfo\fR checks to see whether its \fIcmdName\fR argument
168
exists as a command in \fIinterp\fR.
169
\fIcmdName\fR may include \fB::\fR namespace qualifiers
170
to identify a command in a particular namespace.
171
If the command is not found, then it returns 0.
172
Otherwise it places information about the command
173
in the \fBTcl_CmdInfo\fR structure
174
pointed to by \fIinfoPtr\fR and returns 1.
175
A \fBTcl_CmdInfo\fR structure has the following fields:
176
.CS
177
typedef struct Tcl_CmdInfo {
178
    int isNativeObjectProc;
179
    Tcl_ObjCmdProc *objProc;
180
    ClientData objClientData;
181
    Tcl_CmdProc *proc;
182
    ClientData clientData;
183
    Tcl_CmdDeleteProc *deleteProc;
184
    ClientData deleteData;
185
    Tcl_Namespace *namespacePtr;
186
} Tcl_CmdInfo;
187
.CE
188
The \fIisNativeObjectProc\fR field has the value 1
189
if \fBTcl_CreateObjCommand\fR was called to register the command;
190
it is 0 if only \fBTcl_CreateCommand\fR was called.
191
It allows a program to determine whether it is faster to
192
call \fIobjProc\fR or \fIproc\fR:
193
\fIobjProc\fR is normally faster
194
if \fIisNativeObjectProc\fR has the value 1.
195
The fields \fIobjProc\fR and \fIobjClientData\fR
196
have the same meaning as the \fIproc\fR and \fIclientData\fR
197
arguments to \fBTcl_CreateObjCommand\fR;
198
they hold information about the object-based command procedure
199
that the Tcl interpreter calls to implement the command.
200
The fields \fIproc\fR and \fIclientData\fR
201
hold information about the string-based command procedure
202
that implements the command.
203
If \fBTcl_CreateCommand\fR was called for this command,
204
this is the procedure passed to it;
205
otherwise, this is a compatibility procedure
206
registered by \fBTcl_CreateObjCommand\fR
207
that simply calls the command's
208
object-based procedure after converting its string arguments to Tcl objects.
209
The field \fIdeleteData\fR is the ClientData value
210
to pass to \fIdeleteProc\fR;  it is normally the same as
211
\fIclientData\fR but may be set independently using the
212
\fBTcl_SetCommandInfo\fR procedure.
213
The field \fInamespacePtr\fR holds a pointer to the
214
Tcl_Namespace that contains the command.
215
.PP
216
\fBTcl_SetCommandInfo\fR is used to modify the procedures and
217
ClientData values associated with a command.
218
Its \fIcmdName\fR argument is the name of a command in \fIinterp\fR.
219
\fIcmdName\fR may include \fB::\fR namespace qualifiers
220
to identify a command in a particular namespace.
221
If this command does not exist then \fBTcl_SetCommandInfo\fR returns 0.
222
Otherwise, it copies the information from \fI*infoPtr\fR to
223
Tcl's internal structure for the command and returns 1.
224
Note that this procedure allows the ClientData for a command's
225
deletion procedure to be given a different value than the ClientData
226
for its command procedure.
227
Note that \fBTcl_SetCmdInfo\fR will not change a command's namespace;
228
you must use \fBTcl_RenameCommand\fR to do that.
229
.PP
230
\fBTcl_GetCommandName\fR provides a mechanism for tracking commands
231
that have been renamed.
232
Given a token returned by \fBTcl_CreateObjCommand\fR
233
when the command was created, \fBTcl_GetCommandName\fR returns the
234
string name of the command.  If the command has been renamed since it
235
was created, then \fBTcl_GetCommandName\fR returns the current name.
236
This name does not include any \fB::\fR namespace qualifiers.
237
The command corresponding to \fItoken\fR must not have been deleted.
238
The string returned by \fBTcl_GetCommandName\fR is in dynamic memory
239
owned by Tcl and is only guaranteed to retain its value as long as the
240
command isn't deleted or renamed;  callers should copy the string if
241
they need to keep it for a long time.
242
.PP
243
 
244
.SH "SEE ALSO"
245
Tcl_CreateCommand, Tcl_ResetResult, Tcl_SetObjResult
246
 
247
.SH KEYWORDS
248
bind, command, create, delete, namespace, object

powered by: WebSVN 2.1.0

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