top of page

Package
 

Tcl supports grouping multiple procedures or compiled "C" code modules into a single entity referred to as a package. A package may consist of a single file, multiple files or a mix of compiled and Tcl script files.
 Some packages (like http and Tk) are provided in the base Tcl distribution, and many more are included in the tcllib collection. (See tcllib.sourceforge.net)

 To access a package from a script: 
1. Make certain that the auto_path global variable includes the path to the package you wish to include. The standard Tcl distributions include the proper paths by default.
2. Include a line like this in the application that uses a package:
 package require nameOfPackage You script will need a separate package require command for each package you wish to include. 

 To create a package, you'll need 
1. to include a package provide command like package provide nameOfPackage revisionNumber 
 in each file that's included in the package
2. create a pkgIndex.tcl file to describe the files in the package. This can be done with the pkg_mkIndex command. 

package require name ?revision?
Tells the interpreter to find a package with the given name and optional revision number. If the revision number is absent, the largest revision available is used.


package provide  name revision 
Declares that this file provides an implementation of a specific revision of a package. A file may include only one package provide command.


pkg_mkIndex libdir file1 ... filen
Creates an index file (pkgIndex.tcl) in libdir from the source code modules listed as file1 - filen. Each proc in the files will be listed in the index file, with a reference to the source code module that contains it.
The file descriptors may be any number of strings using the same format as arguments to the glob command.  Two other commands are related to finding packages and processing them. Your code will not need to use these, but you may find them useful in understanding how the system behaves.


 

© 2015 Thirumurugan

bottom of page