Native Inspect Manual (H06.04+)

Using Tcl Scripting
Native Inspect Manual528122-005
5-3
Namespaces and Package Loading Rules
Procedure headers (one or more)
°
Abstract
°
Arguments
°
Results
Namespaces and Package Loading Rules
Tcl supports packages and hierarchical namespaces.
Creating Packages
Packages are libraries of Tcl code that you can create using the Tcl package provide
command:
# mySub.tcl
package provide mySub 1.0
# my package code
Putting a Package in a Namespace
The global namespace contains the built-in Tcl commands, such as set, puts, and
open. You should create your Tcl packages in your own child namespace, not in the
global namespace, which should be the exclusive property of the application.
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