namespace export
Sets the commands of the current namespace that other code can import.
namespace export ?-clear? ?PATTERN ...?
Description
Adds each PATTERN to the export list of the current namespace. A PATTERN is a glob pattern of command names, with no namespace in it. namespace import imports only the exported commands, and an ensemble with no -subcommands and no -map has the exported commands as its subcommands.
-clear empties the list before it adds the patterns. With no PATTERN and no -clear, it gives the export list.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| PATTERN | glob pattern | none | The names of commands to export. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
-clear | flag | none | Empties the export list before it adds the patterns. |
-clear
Empties the export list before it adds the patterns.
With -clear, the export list is only the patterns of this call. namespace export -clear with no PATTERN empties the list.
% namespace eval m {namespace export -clear s*; namespace export}
s*
% namespace eval m {namespace export -clear; namespace export}A flag has no value to check.
Returns
The export list with no PATTERN, or an empty string.
Examples
% namespace eval m {
> proc add {a b} {expr {$a + $b}}
> proc sub {a b} {expr {$a - $b}}
> namespace export add sub
> }
> namespace eval m {namespace export}
add sub
% namespace eval m2 {namespace export a*; namespace export b*; namespace export}
a* b*
Errors
% namespace eval m {namespace export ::x::y}
invalid export pattern "::x::y": pattern can't specify a namespace
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1