1Tcl_Namespace(3) Tcl Library Procedures Tcl_Namespace(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_AppendExportList, Tcl_CreateNamespace, Tcl_DeleteNamespace, Tcl_Ex‐
9 port, Tcl_FindCommand, Tcl_FindNamespace, Tcl_ForgetImport, Tcl_GetCur‐
10 rentNamespace, Tcl_GetGlobalNamespace, Tcl_GetNamespaceUnknownHandler,
11 Tcl_Import, Tcl_SetNamespaceUnknownHandler - manipulate namespaces
12
14 #include <tcl.h>
15
16 Tcl_Namespace *
17 Tcl_CreateNamespace(interp, name, clientData, deleteProc)
18
19 Tcl_DeleteNamespace(nsPtr)
20
21 int
22 Tcl_AppendExportList(interp, nsPtr, objPtr)
23
24 int
25 Tcl_Export(interp, nsPtr, pattern, resetListFirst)
26
27 int
28 Tcl_Import(interp, nsPtr, pattern, allowOverwrite)
29
30 int
31 Tcl_ForgetImport(interp, nsPtr, pattern)
32
33 Tcl_Namespace *
34 Tcl_GetCurrentNamespace(interp)
35
36 Tcl_Namespace *
37 Tcl_GetGlobalNamespace(interp)
38
39 Tcl_Namespace *
40 Tcl_FindNamespace(interp, name, contextNsPtr, flags)
41
42 Tcl_Command
43 Tcl_FindCommand(interp, name, contextNsPtr, flags)
44
45 Tcl_Obj *
46 Tcl_GetNamespaceUnknownHandler(interp, nsPtr)
47
48 int
49 Tcl_SetNamespaceUnknownHandler(interp, nsPtr, handlerPtr)
50
52 Tcl_Interp *interp (in/out) The interpreter in
53 which the name‐
54 space exists and
55 where name lookups
56 are performed.
57 Also where error
58 result messages
59 are written.
60
61 const char *name (in) The name of the
62 namespace or com‐
63 mand to be created
64 or accessed.
65
66 ClientData clientData (in) A context pointer
67 by the creator of
68 the namespace.
69 Not interpreted by
70 Tcl at all.
71
72 Tcl_NamespaceDeleteProc *deleteProc (in) A pointer to func‐
73 tion to call when
74 the namespace is
75 deleted, or NULL
76 if no such call‐
77 back is to be per‐
78 formed.
79
80 Tcl_Namespace *nsPtr (in) The namespace to
81 be manipulated, or
82 NULL (for other
83 than Tcl_Delete‐
84 Namespace) to ma‐
85 nipulate the cur‐
86 rent namespace.
87
88 Tcl_Obj *objPtr (out) A reference to an
89 unshared value to
90 which the function
91 output will be
92 written.
93
94 const char *pattern (in) The glob-style
95 pattern (see
96 Tcl_StringMatch)
97 that describes the
98 commands to be im‐
99 ported or ex‐
100 ported.
101
102 int resetListFirst (in) Whether the list
103 of export patterns
104 should be reset
105 before adding the
106 current pattern to
107 it.
108
109 int allowOverwrite (in) Whether new com‐
110 mands created by
111 this import action
112 can overwrite ex‐
113 isting commands.
114
115 Tcl_Namespace *contextNsPtr (in) The location in
116 the namespace hi‐
117 erarchy where the
118 search for a name‐
119 space or command
120 should be con‐
121 ducted relative to
122 when the search
123 term is not rooted
124 at the global
125 namespace. NULL
126 indicates the cur‐
127 rent namespace.
128
129 int flags (in) OR-ed combination
130 of bits control‐
131 ling how the
132 search is to be
133 performed. The
134 following flags
135 are supported:
136 TCL_GLOBAL_ONLY
137 (indicates that
138 the search is al‐
139 ways to be con‐
140 ducted relative to
141 the global name‐
142 space), TCL_NAME‐
143 SPACE_ONLY (just
144 for Tcl_FindCom‐
145 mand; indicates
146 that the search is
147 always to be con‐
148 ducted relative to
149 the context name‐
150 space), and
151 TCL_LEAVE_ERR_MSG
152 (indicates that an
153 error message
154 should be left in
155 the interpreter if
156 the search fails.)
157
158 Tcl_Obj *handlerPtr (in) A script fragment
159 to be installed as
160 the unknown com‐
161 mand handler for
162 the namespace, or
163 NULL to reset the
164 handler to its de‐
165 fault.
166______________________________________________________________________________
167
169 Namespaces are hierarchic naming contexts that can contain commands and
170 variables. They also maintain a list of patterns that describes what
171 commands are exported, and can import commands that have been exported
172 by other namespaces. Namespaces can also be manipulated through the
173 Tcl command namespace.
174
175 The Tcl_Namespace structure encapsulates a namespace, and is guaranteed
176 to have the following fields in it: name (the local name of the name‐
177 space, with no namespace separator characters in it, with empty denot‐
178 ing the global namespace), fullName (the fully specified name of the
179 namespace), clientData, deleteProc (the values specified in the call to
180 Tcl_CreateNamespace), and parentPtr (a pointer to the containing name‐
181 space, or NULL for the global namespace.)
182
183 Tcl_CreateNamespace creates a new namespace. The deleteProc will have
184 the following type signature:
185
186 typedef void Tcl_NamespaceDeleteProc(
187 ClientData clientData);
188
189 Tcl_DeleteNamespace deletes a namespace, calling the deleteProc defined
190 for the namespace (if any).
191
192 Tcl_AppendExportList retrieves the export patterns for a namespace
193 given namespace and appends them (as list items) to objPtr.
194
195 Tcl_Export sets and appends to the export patterns for a namespace.
196 Patterns are appended unless the resetListFirst flag is true.
197
198 Tcl_Import imports commands matching a pattern into a namespace. Note
199 that the pattern must include the name of the namespace to import from.
200 This function returns an error if an attempt to import a command over
201 an existing command is made, unless the allowOverwrite flag has been
202 set.
203
204 Tcl_ForgetImport removes imports matching a pattern.
205
206 Tcl_GetCurrentNamespace returns the current namespace for an inter‐
207 preter.
208
209 Tcl_GetGlobalNamespace returns the global namespace for an interpreter.
210
211 Tcl_FindNamespace searches for a namespace named name within the con‐
212 text of the namespace contextNsPtr. If the namespace cannot be found,
213 NULL is returned.
214
215 Tcl_FindCommand searches for a command named name within the context of
216 the namespace contextNsPtr. If the command cannot be found, NULL is
217 returned.
218
219 Tcl_GetNamespaceUnknownHandler returns the unknown command handler for
220 the namespace, or NULL if none is set.
221
222 Tcl_SetNamespaceUnknownHandler sets the unknown command handler for the
223 namespace. If handlerPtr is NULL, then the handler is reset to its de‐
224 fault.
225
227 Tcl_CreateCommand(3), Tcl_ListObjAppendList(3), Tcl_SetVar(3)
228
230 namespace, command
231
232
233
234Tcl 8.5 Tcl_Namespace(3)