item2
Next»

contents

 

Introduction - 1

Background - 2

Deployment - 3

Starkits - 4

Tclkit - 5

Advanced topics - 6

Repositories - 7

Server apps - 8

Who uses this - 9

Examples - 10

Conclusion - 11

 

Acknowledgements

References

4.2 - Starkits - a simple example

To build a Starkit you need

  • Tclkit for your platform - which can be obtained from the “Tclkit Home Page” at [9]
  • on Windows you’ll also need tclkitsh - the console mode version of Tclkit
  • the SDX utility - which can be obtained via the SDX Download Page

SDX - the Starkit Developer eXtension is a Starkit containing a collection of scripts for creating and manipulating Starkits. You can list the available scripts by running:

    $ sdx help

Firstly, we’ll need a small Tcl/Tk script that serves as our application - in this example we’ll use the ubiquitous “Hello World” script which we’ll put in a file hello.tcl:

    package require Tk
    button .b -text “Hello world” -command bell
    pack .b

Note that we explicitly specify “package require Tk” - this is because Tk is a dynamically loadable extension within Tclkit and must be explicitly loaded if required.

Now, we use the SDX qwrap command to do a “quick wrap” of this script into a Starkit:

    $ sdx qwrap hello.tcl

The result will be a file called hello.kit - the resulting Starkit. On Windows, there’ll also be a file hello.bat - which just invokes hello.kit using Tclkit. To invoke the Starkit, on Windows just invoke “hello” or on Unix invoke “./hello.kit”.

So, what did qwrap do for us? To find out, we use another SDX feature to unwrap the script so we can examine its contents

    $ sdx unwrap hello.kit

The result is a directory called hello.vfs which contains a copy of the contents of the Starkit virtual filesystem:

    hello.vfs
    |-- main.tcl
    `-- lib
        `-- app-hello
            |-- hello.tcl
            `-- pkgIndex.tcl

The first thing to note is the directory structure. SDX qwrap implements the recommended Starkit convention - storing the application code as a package with the app- prefix. This is done for convenience and consistency - all code within the Starkit is within a package, and application code can be easily distinguished from libraries and packages.

Main.tclis the script that is run whenever a Starkit starts. Looking at its contents, we see sdx qwrap has generated:

    package require starkit
    starkit::startup
    package require app-hello

The first line loads the Starkit runtime package - a small (less than 100 lines) pure Tcl package that manages the Starkit start-up sequence (amongst other things, it mounts the Starkit VFS).

In the second line the starkit::startup procedure performs a few standard startup tasks - it initialises the starkit::topdir variable to point to the top directory in the Starkit VFS (which can be used to relatively access files in the VFS). It also adds the Starkit lib directory to the Tcl auto_path variable, thus making available any packages stored in that directory.

And finally, the “package require” causes the hello.tcl script to be sourced from within the lib/app-hello directory inside the hello.kit VFS.

Note also that qwrap has created the lib/app-hello directory and copied hello.tcl into there (adding a “package provide app-hello” line if necessary) and created a pkgIndex.tcl file to enable auto loading by Tcl. If there is no “package provide ..” line in the source code qwrap will add one to the pkgIndex.tcl for you.

We can now make changes to hello.tcl, but we have two copies - our original one, plus the copy under hello.vfs.

There are two ways to address this:

  • we can either remove our original hello.tcl and just make changes to the one under hello.vfs. script.
  • alternatively, a convenient technique for developers (at least, on Unix) is to replace hello.vfs/lib/app-hello/hello.tcl with a symbolic link to the hello.tcl script

Assuming we have made changes, we can recreate hello.kit using the SDX wrap command:

    $ sdx wrap hello.kit

see also

Starkit Home Page

Tclkit Home Page

Metakit Home Page

SDX Utility

Wikit Home Page

Tclers' Wiki

Author's Website

Updated paper, by Steve Landers, as presented at Tcl/Tk 2002 conference - see also original PDF.

Papers & Presentations