Hamster-Skripte: modules
Creations of modules
A module usually often contains required functions (Subroutinen) or constants. The module should stand in the module catalogue (what usually corresponds to the main catalogue of the hamster) and the file extension for a module should be ".hsm", if one would like to treat it about the hamster's menu directly.
Compared to normal scripts a module contains an initialization part. This is automatically implemented before use of the script.
Beginning with the Preprozessor order " *! Initialize " the initialization part can contain usual script code. This is automatically implemented with use of the module by a script.
The initialization part must be finished with a return value. Besides, a return value of 0 means a successful initialization. Another value than 0 becomes from the appealing script, considers mistake by the initialization of the module.
*! Initialize
Debug (255, " < < < modules 'modulename.hsm' > > > ")
Return (0)
The initialization code of a module is called in the global context. All in the initialization part of a script to defined variables are therefore global variables.
*! Initialize
Debug (255, " < < < modules douglas_adams.hsm ' > > > ")
Var ($THE_ANSWER)
$THE_ANSWER = 42
Return (0)
It is advisable to allow to begin all variables and Subroutinenamen within a script with the name of the module to avoid overlaps of variables and Subroutinenamen of different programmers.
*! Initialize
Debug (255, " < < < modules 'modulename.hsm' > > > ")
Var ($modulename_hsm_Counter)
$module_name_hsm_Counter = 0
Return (0)
Sub modulename_hsm_ThisSubOnlyNeededWithinM odule
*...
Endsub
Modules apply
Before the first use of a module this must with the Preprozessorbefehl " *! Load are loaded " by the script.
*! Load hamster.hsm
*! Load htime.hsm
A module can contain a Preprozessorbefehl to the shop of another module in the initialization part. All the same how often the Preprozessorbefehl it is found(seems) to the shop of a module in the script, only once one and the same script is loaded always and is initialized.
All modules are loaded before implementing the script. The initialization code of the modules is implemented in reverse loading order.