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