1 |
578 |
markom |
'\"
|
2 |
|
|
'\" Copyright (c) 1998 Lucent Technologies, 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 |
|
|
'\" SCCS: %W%
|
8 |
|
|
'\"
|
9 |
|
|
.so man.macros
|
10 |
|
|
.TH Tcl_AddInterpResolvers 3 8.0 Tcl "Tcl Library Procedures"
|
11 |
|
|
.BS
|
12 |
|
|
.SH NAME
|
13 |
|
|
Tcl_AddInterpResolvers, Tcl_GetInterpResolvers, Tcl_RemoveInterpResolvers, Tcl_SetNamespaceResolvers, Tcl_GetNamespaceResolvers \- change the name resolution rules for commands/variables
|
14 |
|
|
.SH SYNOPSIS
|
15 |
|
|
.nf
|
16 |
|
|
\fB#include \fR
|
17 |
|
|
.sp
|
18 |
|
|
void
|
19 |
|
|
\fBTcl_AddInterpResolvers\fR(\fIinterp, name, cmdProc, varProc, compiledVarProc\fR)
|
20 |
|
|
.sp
|
21 |
|
|
int
|
22 |
|
|
\fBTcl_GetInterpResolvers\fR(\fIinterp, name, resInfoPtr\fR)
|
23 |
|
|
.sp
|
24 |
|
|
int
|
25 |
|
|
\fBTcl_RemoveInterpResolvers\fR(\fIinterp, name\fR)
|
26 |
|
|
.sp
|
27 |
|
|
void
|
28 |
|
|
\fBTcl_SetNamespaceResolvers\fR(\fInamespacePtr, cmdProc, varProc, compiledVarProc\fR)
|
29 |
|
|
.sp
|
30 |
|
|
int
|
31 |
|
|
\fBTcl_GetNamespaceResolvers\fR(\fInamespacePtr, resInfoPtr\fR)
|
32 |
|
|
.SH ARGUMENTS
|
33 |
|
|
.AS Tcl_ResolveCompiledVarProc *compiledVarProc
|
34 |
|
|
.AP Tcl_Interp *interp in
|
35 |
|
|
Interpreter whose name resolution rules are being queried or modified.
|
36 |
|
|
.AP char *name in
|
37 |
|
|
Name for a group of name resolution procedures.
|
38 |
|
|
.AP Tcl_ResolveCmdProc *cmdProc in
|
39 |
|
|
Procedure which will be used to resolve command names.
|
40 |
|
|
.AP Tcl_ResolveVarProc *varProc in
|
41 |
|
|
Procedure which will be used to resolve variable names at run time.
|
42 |
|
|
.AP Tcl_ResolveCompiledVarProc *compiledVarProc in
|
43 |
|
|
Procedure which will be used to resolve variable names at compile time.
|
44 |
|
|
.AP Tcl_ResolverInfo *resInfoPtr out
|
45 |
|
|
Returns the resolution procedures that are currently in effect for
|
46 |
|
|
a particular namespace or for a particular name resolution scheme
|
47 |
|
|
in the interpreter.
|
48 |
|
|
.AP Tcl_Namespace *namespacePtr in
|
49 |
|
|
Namespace whose name resolution rules are being queried or modified.
|
50 |
|
|
.BE
|
51 |
|
|
|
52 |
|
|
.SH DESCRIPTION
|
53 |
|
|
.PP
|
54 |
|
|
These procedures make it possible to change the way that Tcl
|
55 |
|
|
resolves command/variable names. The name resolution rules are
|
56 |
|
|
changed by supplying three procedures: \fIcmdProc\fR, \fIvarProc\fR, and
|
57 |
|
|
\fIcompiledVarProc\fR. See the section \fBHOW NAME RESOLUTION PROCEDURES
|
58 |
|
|
WORK\fR for details about these procedures.
|
59 |
|
|
.PP
|
60 |
|
|
The name resolution rules can be changed for a particular namespace,
|
61 |
|
|
for an entire interpreter, or both. When a name needs to be resolved,
|
62 |
|
|
Tcl handles it as follows. The name resolution scheme for the
|
63 |
|
|
current namespace is consulted first. Each of the name resolution
|
64 |
|
|
schemes for the interpreter are consulted next. Finally, Tcl uses
|
65 |
|
|
the default rules for name resolution as described for the
|
66 |
|
|
\fBnamespace\fR command.
|
67 |
|
|
.PP
|
68 |
|
|
\fBTcl_AddInterpResolver\fR adds a set of name resolution procedures
|
69 |
|
|
to an interpreter. The procedures are identified by a string \fIname\fR,
|
70 |
|
|
so they can be queried or deleted later on. All of the name resolution
|
71 |
|
|
schemes for the interpreter are kept on a list, and they are consulted
|
72 |
|
|
in order from most- to least-recently added. For example, suppose one
|
73 |
|
|
extension adds a name resolution scheme called "fred", and another
|
74 |
|
|
extension adds another scheme called "barney". When a name is resolved,
|
75 |
|
|
the "barney" scheme will be consulted first, followed by the "fred"
|
76 |
|
|
scheme, if necessary.
|
77 |
|
|
.PP
|
78 |
|
|
\fBTcl_GetInterpResolver\fR looks for a particular name resolution
|
79 |
|
|
scheme in an interpreter. If the \fIname\fR is recognized, this
|
80 |
|
|
procedure returns a non-zero value along with pointers to the
|
81 |
|
|
name resolution procedures in the \fIresInfoPtr\fR structure. Otherwise,
|
82 |
|
|
the procedure returns 0.
|
83 |
|
|
.PP
|
84 |
|
|
\fBTcl_RemoveInterpResolver\fR looks for a particular name resolution
|
85 |
|
|
scheme in an interpreter. If the \fIname\fR is recognized, this
|
86 |
|
|
procedure deletes the scheme and returns a non-zero value. Otherwise,
|
87 |
|
|
it returns 0.
|
88 |
|
|
.PP
|
89 |
|
|
\fBTcl_SetNamespaceResolver\fR sets the name resolution procedures
|
90 |
|
|
for a particular namespace. Unlike an interpreter, a namespace can
|
91 |
|
|
have only one name resolution scheme in effect at any given time.
|
92 |
|
|
.PP
|
93 |
|
|
\fBTcl_GetNamespaceResolver\fR returns the name resolution procedures
|
94 |
|
|
for a particular namespace. If the namespace has a special name
|
95 |
|
|
resolution scheme, this procedure returns a non-zero value along
|
96 |
|
|
with pointers to the name resolution procedures in the \fIresInfoPtr\fR
|
97 |
|
|
structure. Otherwise, the procedure returns 0.
|
98 |
|
|
.SH "HOW NAME RESOLUTION PROCEDURES WORK"
|
99 |
|
|
A name resolution scheme is enforced by three name resolution procedures.
|
100 |
|
|
The \fIcmdProc\fR procedure is used to resolve command names. It must
|
101 |
|
|
conform to the following type:
|
102 |
|
|
.CS
|
103 |
|
|
typedef int Tcl_ResolveCmdProc(Tcl_Interp* \fIinterp\fR,
|
104 |
|
|
char* \fIname\fR, Tcl_Namespace* \fIcontext\fR, int \fIflags\fR,
|
105 |
|
|
Tcl_Command* \fIrPtr\fR);
|
106 |
|
|
.CE
|
107 |
|
|
The \fIinterp\fR argument is the interpreter performing the resolution;
|
108 |
|
|
\fIname\fR is the command name being resolved; \fIcontext\fR is the
|
109 |
|
|
namespace context containing the command reference; and \fIflags\fR
|
110 |
|
|
may contain TCL_LEAVE_ERR_MSG.
|
111 |
|
|
.PP
|
112 |
|
|
If this procedure recognizes the command \fIname\fR, it should
|
113 |
|
|
store the Tcl_Command token for that command in the \fIrPtr\fR
|
114 |
|
|
argument and return TCL_OK. If this procedure doesn't recognize
|
115 |
|
|
the command \fIname\fR, it should return TCL_CONTINUE, and the
|
116 |
|
|
name resolution will continue with another procedure or with the
|
117 |
|
|
default Tcl resolution scheme. If this procedure recognizes
|
118 |
|
|
the command \fIname\fR, but for some reason the command is
|
119 |
|
|
invalid, the procedure should return TCL_ERROR. If the \fIflags\fR
|
120 |
|
|
argument contains TCL_LEAVE_ERR_MSG, the procedure should leave
|
121 |
|
|
an error message in the interpreter, explaining why the command
|
122 |
|
|
is invalid.
|
123 |
|
|
.PP
|
124 |
|
|
The \fIvarProc\fR procedure is similar to \fIcmdProc\fR, but it is
|
125 |
|
|
used to resolve variable names encountered at run time. It must
|
126 |
|
|
conform to the following type:
|
127 |
|
|
.CS
|
128 |
|
|
typedef int Tcl_ResolveVarProc(Tcl_Interp* \fIinterp\fR,
|
129 |
|
|
char* \fIname\fR, Tcl_Namespace* \fIcontext\fR, int \fIflags\fR,
|
130 |
|
|
Tcl_Var* \fIrPtr\fR);
|
131 |
|
|
.CE
|
132 |
|
|
The \fIinterp\fR argument is the interpreter performing the resolution;
|
133 |
|
|
\fIname\fR is the variable name being resolved; \fIcontext\fR is the
|
134 |
|
|
namespace context containing the variable reference; and \fIflags\fR
|
135 |
|
|
may contain TCL_GLOBAL_ONLY, TCL_NAMESPACE_ONLY, or TCL_LEAVE_ERR_MSG.
|
136 |
|
|
.PP
|
137 |
|
|
If this procedure recognizes the variable \fIname\fR, it should
|
138 |
|
|
store the Tcl_Var token for that variable in the \fIrPtr\fR
|
139 |
|
|
argument and return TCL_OK. If this procedure doesn't recognize
|
140 |
|
|
the variable \fIname\fR, it should return TCL_CONTINUE, and the
|
141 |
|
|
name resolution will continue with another procedure or with the
|
142 |
|
|
default Tcl resolution scheme. If this procedure recognizes
|
143 |
|
|
the variable \fIname\fR, but for some reason the variable is
|
144 |
|
|
not accessible, the procedure should return TCL_ERROR. If the
|
145 |
|
|
\fIflags\fR argument contains TCL_LEAVE_ERR_MSG, the procedure
|
146 |
|
|
should leave an error message in the interpreter, explaining why
|
147 |
|
|
the variable reference is invalid.
|
148 |
|
|
.PP
|
149 |
|
|
Note that this procedure should look for the TCL_GLOBAL_ONLY and
|
150 |
|
|
TCL_NAMESPACE_ONLY flags. It should handle them appropriately, or
|
151 |
|
|
return TCL_CONTINUE and let Tcl handle the reference. But it should
|
152 |
|
|
not ignore the flags.
|
153 |
|
|
.PP
|
154 |
|
|
Tcl also resolves variables when a body of code is compiled; the
|
155 |
|
|
\fIcompiledVarProc\fR procedure handles that case. It must
|
156 |
|
|
conform to the following type:
|
157 |
|
|
.CS
|
158 |
|
|
typedef int Tcl_ResolveCompiledVarProc(Tcl_Interp* \fIinterp\fR,
|
159 |
|
|
char* \fIname\fR, int \fIlength\fR, Tcl_Namespace* \fIcontext\fR,
|
160 |
|
|
Tcl_ResolvedVarInfo* \fIrPtr\fR);
|
161 |
|
|
.CE
|
162 |
|
|
The \fIinterp\fR argument is the interpreter performing the resolution;
|
163 |
|
|
\fIname\fR is the variable name being resolved; \fIlength\fR is the
|
164 |
|
|
number of bytes in \fIname\fR, which is not a null-terminated
|
165 |
|
|
string; and \fIcontext\fR is the namespace context containing the
|
166 |
|
|
variable reference.
|
167 |
|
|
.PP
|
168 |
|
|
If this procedure recognizes the variable \fIname\fR, it should
|
169 |
|
|
return some information characterizing the variable in the
|
170 |
|
|
\fIrPtr\fR structure. This structure is defined as follows:
|
171 |
|
|
.CS
|
172 |
|
|
typedef struct Tcl_ResolvedVarInfo {
|
173 |
|
|
ClientData \fIidentity\fR;
|
174 |
|
|
Tcl_ResolveRuntimeVarProc *\fIfetchProc\fR;
|
175 |
|
|
Tcl_ResolveVarDeleteProc *\fIdeleteProc\fR;
|
176 |
|
|
} Tcl_ResolvedVarInfo;
|
177 |
|
|
.CE
|
178 |
|
|
The \fIidentity\fR field is an arbitrary value that characterizes
|
179 |
|
|
the variable. Each variable should have a unique identity. Each
|
180 |
|
|
time the compiled code is executed, Tcl will call the \fIfetchProc\fR
|
181 |
|
|
procedure to get the actual variable for a particular \fIidentity\fR
|
182 |
|
|
value. This callback procedure must conform to the following type:
|
183 |
|
|
.CS
|
184 |
|
|
typedef Tcl_Var Tcl_ResolveRuntimeVarProc(Tcl_Interp* \fIinterp\fR,
|
185 |
|
|
ClientData \fIidentity\fR);
|
186 |
|
|
.CE
|
187 |
|
|
The \fIfetchProc\fR procedure takes the \fIinterp\fR interpreter
|
188 |
|
|
and the \fIidentity\fR from compile time and returns a Tcl_Var
|
189 |
|
|
token representing the variable. If for some reason the variable
|
190 |
|
|
can't be found, this procedure should return NULL, and Tcl will
|
191 |
|
|
create a local variable within the call frame of the procedure
|
192 |
|
|
being executed.
|
193 |
|
|
.PP
|
194 |
|
|
When the compiled code is discarded, Tcl calls the \fIdeleteProc\fR
|
195 |
|
|
procedure to release the \fIidentity\fR data. The delete procedure
|
196 |
|
|
must conform to the following type:
|
197 |
|
|
.CS
|
198 |
|
|
typedef void Tcl_ResolveVarDeleteProc(ClientData \fIidentity\fR);
|
199 |
|
|
.CE
|
200 |
|
|
.PP
|
201 |
|
|
In general, the \fIvarProc\fR and \fIcompiledVarProc\fR procedures
|
202 |
|
|
should \fIboth\fR be defined. If the \fIcompiledVarProc\fR is not
|
203 |
|
|
defined, then Tcl will create local variables for any variable
|
204 |
|
|
names that are not recognized within a procedure. If the \fIvarProc\fR
|
205 |
|
|
is not defined, then Tcl will not recognize variables that are
|
206 |
|
|
encountered at runtime. For example, consider the following procedure:
|
207 |
|
|
.CS
|
208 |
|
|
proc foo {args} {
|
209 |
|
|
set anotherRef "1"
|
210 |
|
|
set name "another"
|
211 |
|
|
set ${name}Ref "2"
|
212 |
|
|
}
|
213 |
|
|
.CE
|
214 |
|
|
Suppose that the \fIcompiledVarProc\fR resolves the name
|
215 |
|
|
\fBanotherRef\fR at compile time. The name \fB${name}Ref\fR
|
216 |
|
|
can't be resolved at compile time, so the resolution of that
|
217 |
|
|
name is deferred to run time. If the \fIvarProc\fR procedure
|
218 |
|
|
must intercept the name \fBanotherRef\fR at run time and
|
219 |
|
|
supply the appropriate variable.
|
220 |
|
|
|
221 |
|
|
.SH KEYWORDS
|
222 |
|
|
interpreter, namespace, resolution
|