Modules are used to create re-usable script libraries.
A module provides a collection of constants, variables, functions and classes which typicially serve specific purposes like e.g. loading and displaying fonts (pixelfont.tks) or providing a debug facility (debug.tks).
In conjunction with C/C++ extensions (plugins) modules can be used to define a (reference) user interface for a plugin. An example was a a scripted voice manager for an audio synthesizer which relies on native plugin functions to generate/process waveforms
Each module is associated with a TKS sourcecode file. In order to access specific modules, unique names can be assigned; thats what the module statement does.
Example:
module MMyModule;
A module is typically used by multiple applications which suggests the use of a common directory. The path to this common directory is specified either by the environment variable
TKS_MODULE_PATH, by a registry entry (Win32,
HKLM\Software\TKS\TKS_MODULE_PATH) or by the command line parameter
--modulepath/
-mp.
Please notice the trailing "slashes":
tks -mp 'c:\Programme\tks\modules\'or
tks -mp '/usr/local/tks/modules/'
The project directory has priority over the common module directory which means that if a copy of a module is made in order to customize it for a specific application and placed in the project directory, this copy will be used instead of the archived module.
Classes and constants declared in one module are also visible in all other modules.
Functions need to be declared before their use and are only visible within the module in which they have been declared (and implemented). Functions in other modules can explicitely be accessed by prepending the module's name.
Example:
module Main;
MMyModule.MyFunction(); // assumes a MYModule.MyFunction function
The Main module is the starting point of an application. If the module contains a main() function, this function will be called once the project and/or TKX archive has been loaded successfully.
Example:
module Main;
function main()
{
print "got " + Arguments.numElements + " argument(s).";
}
If the module statement is omitted, Main is assumed (except for temporary modules which do not have names).
If the main() function is missing, the application will terminate after execution of all global statements. This can be used to initialize arrays or run other precalculations (e.g. loading/generating images).
The order of execution is determined, similar to the order of compilation, by the order given in the project file.
For documentation purposes it is highly recommended to add comments..
The keyword // marks the beginning of a line comment, i.e. all following chars are excluded from interpretation.
Example:
// ---- file : mymodule.tks
// ---- author: Bastian Spiegel
The keywords /* und */ are used to exclude a paragraph from interpretation. Unlike the // line comment, these comments may also stretch across several lines.
Nesting of comments is possible yet deprecated since it confuses the syntax highlighting modes of most texteditors (and actually makes no sense either)
Example:
for(int i=0; /* this is an embedded comment */ i++; i<10)
{
/* ..../*do something useful*/... */
}