See Extending Tcl for general information about writing Tcl extensions.
For the person new to Tcl, one might wonder whether there is a difference between the use of the term package and the word extension. Generally, no. Tcl actually has a package command, but there is no extension command. So package is probably the better term to use.
LV writes, on comp.lang.tcl, the following comments about taking a script package from the wiki or other places and installing it:Premise: a user sees a web page, usenet posting, etc. that has tcl code which implements a series of procs. How do they move from this finding into having the ability to package require it?
- Let's pretend, for the purpose of this discussion, that our hypothetical package is called "fschanges".
- Let's pretend that we would find this package at some location on the net - say the web page mentioned above.
- The first thing that the user would need to do is to download the tcl code and save it as a text file. Let's say they save it as fschanges.tcl
- Now, they edit the saved data to ensure that only lines recognized by Tcl are inside the text file.
- Now, the next step is to create a sub-directory inside one of the tclsh's auto_path directories - or into a directory that will be added to the tclsh's auto_path. For the sake of this illustration, let's pretend we are using /usr/lib/tcl8.3 . So the user would create a subdirectory called /usr/lib/tcl8.3/fschanges-0.1/ . The version was included in the directory name so that as things in the extension change, you create a sibling directory called, perhaps, 'fschanges-0.2, to contain the next version. Some people build packages that just install into package name ... that may work for some. But it makes life difficult when code exists that depends on the previous behavior.
- Into that directory, the user would copy the fschanges.tcl file.
- Now, the next step would be to create a pkgIndex.tcl file. Unfortunately, this is the step that doesn't, to me, seem as well documented on the wiki. See pkgmkindex for a page that serves as a central clearing house for info about the process.