Rules with Lua scripts

Scripts written in the Lua programming language can be used to describe the algorithms for checking the values of tags in Process Control rules. Lua scripts provide the capabilities to not only check the values of tags but also to add various information to registered events and process logs.

A Lua script must consist of one or more functions. The names of the functions must be unique among all rules with Lua scripts. A function that is used to track the values of tags is called a trigger function. A trigger function must return a value of true to register an event.

If a variable is indicated in a script, the variable must be initialized either in that specific script (to be applied only in that script) or in a separate global script (to be applied in all rules with Lua scripts). A global script can also contain auxiliary functions that can be used in rules with Lua scripts.

A trigger function is called whenever the value of any tag used in the function is changed. The function is first called when all values of tags used in the function are received.

To obtain the values of a tag, the code of a function contains an entry that looks as follows:

tag'main_tag_parameters[:field_name][@modifier]'[.transmission_direction]

where:

Records for obtaining the values of tags can be used in expressions (for example, assigning values to variables or comparing values).

To perform various operations with a Lua script, you can use auxiliary functions supported by the Server. The names of auxiliary functions begin with an underscore (_).

The main auxiliary functions for adding information via Lua scripts are as follows:

Page top