© Tyl Software Foundation 2019-2021
▶ DYNAMIC SYSTEM MODULES
OverviewDynamic System Modules are internal system modules that handle specialized tasks, such as database management, running processes and network TCP/IP communication. They come in two flavours: single and instance, and will be called single module and instance module respectively.
These modules are like classes in OOP languages. They have variables, functions and a construction or initialization mechanism, and they can be instantiated. But there are some differences in their behavior as Tyl modules, and also between themselves, because they are designed to work in a secure and optimal way to handle their tasks. Most of their variables can't be set a value, meaning they are read only variables, and they must be initialized with a minimum set of variables.
In this chapter we will work with an exemplary module called
shaper, that has
shaperdraws a shape based on data in a location. Let's assume
shapermust know its
shapein order to function. In order to draw, it needs
location, but without
locationit will draw in a location that's based on an internal algorithm.
All dynamic system modules are in caribbean green color, and properties or functions are in denim blue color.
Working with Single ModulesEach system module must be defined or initialized prior to using its functionalities:
shapermodule is initialized in the same way a function is being called, its module name 'shaper', is written first and then comes arguments list. The arguments are in a predefined order, so if for
shapewill be assigned the value 'Circle'. Note that since
shapeis crucial to
shaperfunctionality, the only place that it can be set is in the initialization line.
Since the first token of this initialization line is the module name, it will be regarded as a single module, also known as static or singleton. All access to its variables and functions will be in the format
Once initialized, a single module will be available throughout the program and all merged modules.
So to print
Setting other variables is done as a regular variable assignment:
If a module has all its necessary variables to activate one of its functions, it can call the function:
dataas the circle radius, and will draw the shape.
There is no limit to modules initialization times, and whenever a new set of variables is needed, simply reinitialize the module:
pdata [ 5 100 ]
plocation [ 150 100 ]
shaper 'Rectangle' 10
shaper 'Poligon' pdata plocation
datais a variable with non defined type, meaning it can handle different types, so in the case of the second initialization, it will have a list with the poligon data, and will draw it at
Attention: All variables in the initialization line must be either scalar values or variables. Other programmatic constructs such as string concatanations, functions and parentheses are not allowed!
Single modules are mainly good for preconfiguring them with a set of properties, and then using their functionalities. But if we need some modules with different properties, we better use instance modules.