The Lua Scripting Engine
Do you wish to combine the output of multiple real-time data streams and compare it with historical data? Or selectively browse a large OPC server namespace and return only the items you’re interested in? Perhaps you want a fully automated KPI dashboard that shows daily, weekly and monthly aggregates for all of the above data sources? The Lua scripting engine can achieve all this and more.
Although this sounds impressive, it can also be a little daunting to begin with and raises some questions. What is Lua? Why would I want to customize my system anyway? And how do I even get started?
Firstly, what is Lua and why does system:inmation use it? The Lua scripting language was specifically developed to integrate with software and provide scripting functionality. It is fast, lightweight and relatively simple making it ideal for use with real-time data applications and great for beginners. This flexibility makes it easy to fully automate tasks or perform actions on demand.
In system:inmation Lua scripts are attached to data processing objects that execute the scripts. Depending on the object, a script could be executed once, periodically or when triggered by another item or action. Scripts can be written directly into the DataStudio script editor and executed in real time.
But why customize the system anyway? Well, even though system:inmation has a comprehensive set of configuration options, every data network is different and the way data is gathered and how the user wants to use that data differs from system to system (and user to user). Customizing the system to provide specific information of specific type to each user provides great benefits in productivity and efficiency. Customization naturally includes the automation of tasks and actions, saving the user time and your organization money.
Sounds good so far, so how to get started?
Getting Started – Lua BasicsIf you have some prior experience with scripting languages, you may recognize key elements of the Lua language (the for loops, if, do and while statements will be familiar). With this in mind, there are also things that might be unfamiliar.
Lua is a dynamically typed language, meaning variable types are determined at runtime and can be converted to other types (for example a string defined as “9” can also be number).
In Lua, there is one data structure/container: the table. This can play the role of an array, hash or list.
Data is stored in tables in key/value pairs and they can also work similar to arrays with numbers as keys (in Lua convention, the table key values start at 1 not 0). Although simple, the Lua table is able to perform many of the functions of the individual data structures in other languages.
A good place to start is the Lua.org website , here you can get explanations about the basic commands and functions of Lua. Another good resource is lua-users.org , this wiki provides many scripting examples and how to use the basic (and more advanced) Lua functions.
Not a Programmer? Not a Problem!
The inmation Lua LibraryLua is very well supported online and libraries exist for many common (and not so common) tasks and applications. However, the inmation Lua library contains functions that allow you to, for example, create, delete or enable / disable objects in system:inmation using only one line of code. From there you can set values, make history calls and much more for any object in the system.
The full list of functions and more information on the inmation Lua Library is