| 1 |
'\" |
| 2 |
'\" Copyright (c) 2003 Donal K. Fellows |
| 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 |
'\" Note that some of these functions do not seem to belong, but they |
| 8 |
'\" were all introduced with the same TIP (#139) |
| 9 |
'\" |
| 10 |
.TH Tcl_Namespace 3 8.5 Tcl "Tcl Library Procedures" |
| 11 |
.so man.macros |
| 12 |
.BS |
| 13 |
.SH NAME |
| 14 |
Tcl_AppendExportList, Tcl_CreateNamespace, Tcl_DeleteNamespace, Tcl_Export, Tcl_FindCommand, Tcl_FindNamespace, Tcl_ForgetImport, Tcl_GetCurrentNamespace, Tcl_GetGlobalNamespace, Tcl_GetNamespaceUnknownHandler, Tcl_Import, Tcl_SetNamespaceUnknownHandler \- manipulate namespaces |
| 15 |
.SH SYNOPSIS |
| 16 |
.nf |
| 17 |
\fB#include <tcl.h>\fR |
| 18 |
.sp |
| 19 |
Tcl_Namespace * |
| 20 |
\fBTcl_CreateNamespace\fR(\fIinterp, name, clientData, deleteProc\fR) |
| 21 |
.sp |
| 22 |
\fBTcl_DeleteNamespace\fR(\fInsPtr\fR) |
| 23 |
.sp |
| 24 |
int |
| 25 |
\fBTcl_AppendExportList\fR(\fIinterp, nsPtr, objPtr\fR) |
| 26 |
.sp |
| 27 |
int |
| 28 |
\fBTcl_Export\fR(\fIinterp, nsPtr, pattern, resetListFirst\fR) |
| 29 |
.sp |
| 30 |
int |
| 31 |
\fBTcl_Import\fR(\fIinterp, nsPtr, pattern, allowOverwrite\fR) |
| 32 |
.sp |
| 33 |
int |
| 34 |
\fBTcl_ForgetImport\fR(\fIinterp, nsPtr, pattern\fR) |
| 35 |
.sp |
| 36 |
Tcl_Namespace * |
| 37 |
\fBTcl_GetCurrentNamespace\fR(\fIinterp\fR) |
| 38 |
.sp |
| 39 |
Tcl_Namespace * |
| 40 |
\fBTcl_GetGlobalNamespace\fR(\fIinterp\fR) |
| 41 |
.sp |
| 42 |
Tcl_Namespace * |
| 43 |
\fBTcl_FindNamespace\fR(\fIinterp, name, contextNsPtr, flags\fR) |
| 44 |
.sp |
| 45 |
Tcl_Command |
| 46 |
\fBTcl_FindCommand\fR(\fIinterp, name, contextNsPtr, flags\fR) |
| 47 |
.sp |
| 48 |
Tcl_Obj * |
| 49 |
\fBTcl_GetNamespaceUnknownHandler\fR(\fIinterp, nsPtr\fR) |
| 50 |
.sp |
| 51 |
int |
| 52 |
\fBTcl_SetNamespaceUnknownHandler\fR(\fIinterp, nsPtr, handlerPtr\fR) |
| 53 |
.SH ARGUMENTS |
| 54 |
.AS Tcl_NamespaceDeleteProc allowOverwrite in/out |
| 55 |
.AP Tcl_Interp *interp in/out |
| 56 |
The interpreter in which the namespace exists and where name lookups |
| 57 |
are performed. Also where error result messages are written. |
| 58 |
.AP "const char" *name in |
| 59 |
The name of the namespace or command to be created or accessed. |
| 60 |
.AP ClientData clientData in |
| 61 |
A context pointer by the creator of the namespace. Not interpreted by |
| 62 |
Tcl at all. |
| 63 |
.AP Tcl_NamespaceDeleteProc *deleteProc in |
| 64 |
A pointer to function to call when the namespace is deleted, or NULL |
| 65 |
if no such callback is to be performed. |
| 66 |
.AP Tcl_Namespace *nsPtr in |
| 67 |
The namespace to be manipulated, or NULL (for other than |
| 68 |
\fBTcl_DeleteNamespace\fR) to manipulate the current namespace. |
| 69 |
.AP Tcl_Obj *objPtr out |
| 70 |
A reference to an unshared value to which the function output will be |
| 71 |
written. |
| 72 |
.AP "const char" *pattern in |
| 73 |
The glob-style pattern (see \fBTcl_StringMatch\fR) that describes the |
| 74 |
commands to be imported or exported. |
| 75 |
.AP int resetListFirst in |
| 76 |
Whether the list of export patterns should be reset before adding the |
| 77 |
current pattern to it. |
| 78 |
.AP int allowOverwrite in |
| 79 |
Whether new commands created by this import action can overwrite |
| 80 |
existing commands. |
| 81 |
.AP Tcl_Namespace *contextNsPtr in |
| 82 |
The location in the namespace hierarchy where the search for a |
| 83 |
namespace or command should be conducted relative to when the search |
| 84 |
term is not rooted at the global namespace. NULL indicates the |
| 85 |
current namespace. |
| 86 |
.AP int flags in |
| 87 |
OR-ed combination of bits controlling how the search is to be |
| 88 |
performed. The following flags are supported: \fBTCL_GLOBAL_ONLY\fR |
| 89 |
(indicates that the search is always to be conducted relative to the |
| 90 |
global namespace), \fBTCL_NAMESPACE_ONLY\fR (just for \fBTcl_FindCommand\fR; |
| 91 |
indicates that the search is always to be conducted relative to the |
| 92 |
context namespace), and \fBTCL_LEAVE_ERR_MSG\fR (indicates that an error |
| 93 |
message should be left in the interpreter if the search fails.) |
| 94 |
.AP Tcl_Obj *handlerPtr in |
| 95 |
A script fragment to be installed as the unknown command handler for the |
| 96 |
namespace, or NULL to reset the handler to its default. |
| 97 |
.BE |
| 98 |
.SH DESCRIPTION |
| 99 |
.PP |
| 100 |
Namespaces are hierarchic naming contexts that can contain commands |
| 101 |
and variables. They also maintain a list of patterns that describes |
| 102 |
what commands are exported, and can import commands that have been |
| 103 |
exported by other namespaces. Namespaces can also be manipulated |
| 104 |
through the Tcl command \fBnamespace\fR. |
| 105 |
.PP |
| 106 |
The \fITcl_Namespace\fR structure encapsulates a namespace, and is |
| 107 |
guaranteed to have the following fields in it: \fIname\fR (the local |
| 108 |
name of the namespace, with no namespace separator characters in it, |
| 109 |
with empty denoting the global namespace), \fIfullName\fR (the fully |
| 110 |
specified name of the namespace), \fIclientData\fR, \fIdeleteProc\fR |
| 111 |
(the values specified in the call to \fBTcl_CreateNamespace\fR), and |
| 112 |
\fIparentPtr\fR (a pointer to the containing namespace, or NULL for |
| 113 |
the global namespace.) |
| 114 |
.PP |
| 115 |
\fBTcl_CreateNamespace\fR creates a new namespace. The |
| 116 |
\fIdeleteProc\fR will have the following type signature: |
| 117 |
.PP |
| 118 |
.CS |
| 119 |
typedef void \fBTcl_NamespaceDeleteProc\fR( |
| 120 |
ClientData \fIclientData\fR); |
| 121 |
.CE |
| 122 |
.PP |
| 123 |
\fBTcl_DeleteNamespace\fR deletes a namespace, calling the |
| 124 |
\fIdeleteProc\fR defined for the namespace (if any). |
| 125 |
.PP |
| 126 |
\fBTcl_AppendExportList\fR retrieves the export patterns for a |
| 127 |
namespace given namespace and appends them (as list items) to |
| 128 |
\fIobjPtr\fR. |
| 129 |
.PP |
| 130 |
\fBTcl_Export\fR sets and appends to the export patterns for a |
| 131 |
namespace. Patterns are appended unless the \fIresetListFirst\fR flag |
| 132 |
is true. |
| 133 |
.PP |
| 134 |
\fBTcl_Import\fR imports commands matching a pattern into a |
| 135 |
namespace. Note that the pattern must include the name of the |
| 136 |
namespace to import from. This function returns TCL_ERROR if |
| 137 |
an attempt to import a command over an existing command is made, |
| 138 |
unless the \fIallowOverwrite\fR flag has been set. |
| 139 |
.PP |
| 140 |
\fBTcl_ForgetImport\fR removes imports matching a pattern. |
| 141 |
.PP |
| 142 |
\fBTcl_GetCurrentNamespace\fR returns the current namespace for an |
| 143 |
interpreter. |
| 144 |
.PP |
| 145 |
\fBTcl_GetGlobalNamespace\fR returns the global namespace for an |
| 146 |
interpreter. |
| 147 |
.PP |
| 148 |
\fBTcl_FindNamespace\fR searches for a namespace named \fIname\fR |
| 149 |
within the context of the namespace \fIcontextNsPtr\fR. If the |
| 150 |
namespace cannot be found, NULL is returned. |
| 151 |
.PP |
| 152 |
\fBTcl_FindCommand\fR searches for a command named \fIname\fR within |
| 153 |
the context of the namespace \fIcontextNsPtr\fR. If the command |
| 154 |
cannot be found, NULL is returned. |
| 155 |
.PP |
| 156 |
\fBTcl_GetNamespaceUnknownHandler\fR returns the unknown command handler |
| 157 |
for the namespace, or NULL if none is set. |
| 158 |
.PP |
| 159 |
\fBTcl_SetNamespaceUnknownHandler\fR sets the unknown command handler for |
| 160 |
the namespace. If \fIhandlerPtr\fR is NULL, then the handler is reset to |
| 161 |
its default. |
| 162 |
.SH "SEE ALSO" |
| 163 |
Tcl_CreateCommand(3), Tcl_ListObjAppendList(3), Tcl_SetVar(3) |
| 164 |
.SH KEYWORDS |
| 165 |
namespace, command |