1. TkScript Reference Guide » Modules

reference guide | Modules

Table of Contents:

1. Script modules
A script module represents a single TkScript source code file.
Modules can contain
  • namespace
  • class
  • function
  • variable
  • constant

declarations as well as
  • global initialization statements that are run before the main() function is called.
1.1. Project files
A script project that uses more than one source file must have a project file that lists all sources, see Projects and TKX archives.
Simple example for a project file myproject.tkp:
1.2. Recommendation on how to structure your source codes
You should
  • Use classes if possible
    • The parser for classes is newer and supports more features
    • Classes can contain static methods (to replace module functions)
    • Each class should have its own sourcefile which is named after the class
      • If the class name is e.g. MyClass, the module name should be "MMyClass" and the file name should be "MyClass.tks"
  • Use a main function if possible
    • If you don't, not all global initializer statements may be run
  • Place the main function in a file named "main.tks", module name must be "Main".
    • the default module name is "Main" so be careful to use the "module" statement in the other source files
2. Module names
  1. TkScript Reference Guide » Modules » Module names
Each module has to be assigned a unique module name:

// ---- file: myscript.tks
// ---- purpose: just a simple example module
module MMyScript; // <-- assign module name

print "hello, world."; // <-- initialization code, will be run before main() function
3. Common module include directory
  1. TkScript Reference Guide » Modules » Common module include directory
Project file entries whose filename starts with mod: are searched in the TKS_MODULE_PATH.
The included files will be "statically linked" in a packaged application/x-tkx or application/x-tsl file.
This mechanism was mainly used before the "script library" feature was added to TkScript.
It may still be useful for mini-libraries.

auto-generated by "DOG", the TkScript document generator. Wed, 31/Dec/2008 15:53:35