Native Inspect Manual (H06.03+)

Table Of Contents
Using Tcl Scripting
Native Inspect Manual528122-003
4-4
Namespaces and Package Loading Rules
For example, to put package code in a namespace, use the namespace eval
command. This example puts a package in a namespace of the same name:
# mySub.tcl
package provide mySub 1.0
namespace eval ::mySub:: {
# my package code
}
# More code
In this example, the namespace ::mySub:: contains the package mySub.
When your package is installed on a system, Tcl scripts can use your package by
referring to its namespace, not its actual location.
It is important to create your packages in your own namespaces to avoid conflicts.
Each exported subsystem command must be referenced by namespace.
Other Scripts Must Explicitly Require Your Package:
Any script that uses your package must explicitly require the package, as follows:
# In an app or another package
package require mySub
Explicitly Export Your Public Commands: Your package should export its public
commands (but not its private commands), as follows:
namespace eval ::mySub::: {
namespace export {[a-z]*}
}
proc ::mySub::myPublicProc{} {...}
Each namespace exports symbols that can be explicitly included, and unambiguously
defined. The definition can be nested in the namespace itself (without the namespace
qualifier) or declared as a member of the namespace, with the namespace name
qualified in the proc name, as follows:
#--------------------------------------------------------
# Syntax: dcba <context> <craddr> [ <count> ]
#-------------------------------------------------------------
proc ::mySub::dcba { context craddr {count 1} } {
...
}
...
If a Tcl script is to use the commands in mySub, the caller need only reference the
package as follows:
package require mySub