Version 1 of Package tips and tricks

Updated 2009-02-13 08:28:18 by arjen

Arjen Markus (13 february 2009) Just another page containing some tips and tricks, this one is about packages.

Whether you get a package from the teapot repository or from the distribution directly or ..., normally all you need to do is:

   package require NAME

to load all parts of a package NAME and start using it.

Sometimes, however, you may want a bit of introspection:

  • Where is the package installed?
  • What DLLs or shared objects are involved?
  • What version have I loaded?

Here are some answers:

Where are package looked for?

Tcl uses the variable auto_path to look for a package, a list of directories to search. So if you want it to look in other directories as well, simply append these directories to this variable.

Where is a particular package installed?

Here is a trick Andreas Kupries came up with to find out just where the files are located:

    package ifneeded NAME [package require NAME]

This command will return the exact command to get the package. It works regardless of the type of package: a Tcl-only package, a binary extension or a Tcl module. You need to interpret the command yourself, but it contains the exact location.

(If you want to find a particular version, add that information to the "package require" part)

What DLLs or shared objects are involved?

The following command returns information about the various DLLs/shared objects you currently have loaded into the interpreter:

    info loaded

What version have I loaded?

The simplest way to find out what version you have loaded is to repeat the "package require" command. As it has been loaded already, nothing in particular is done, but you do get the version number.