The Lua Scripting Engine

Written by Edward Spink on Tuesday, 04 July 2017. Posted in General

The Lua Scripting engine is an integral part of system:inmation’s design. Fully embedded within the system, it allows the user to completely customize the management of their data network.

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 Basics

If 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 website , here you can get explanations about the basic commands and functions of Lua. Another good resource is , this wiki provides many scripting examples and how to use the basic (and more advanced) Lua functions.

Not a Programmer? Not a Problem!

Even if you have no previous scripting experience, it is easy to get started with Lua. Complete beginners to programming can quickly grasp the basics and write short but effective scripts. The system:inmation specific Lua library (see below) makes it easy to create and manipulate objects in your system. Start small, by performing calculations with data in your system then move up to creating objects and entire KPI models. In system:inmation, the Lua engine seamlessly interfaces with the C++ engine underneath the hood. So, with just little bit of Lua scripting experience you can leverage the power of the system to your own benefit.

The inmation Lua Library

Lua 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 available here. If you want to use functions from other libraries, simply add them as Lua script libraries to objects in the I/O model tree. Then any object below in the tree can access those functions by calling the library name with the “require” command.

Ready to Start?

Ok then, make sure you have system:inmation installed then go to Using Lua Scripting Jump Start . Here you will find a step by step guide to using Lua in system:inmation and begin to fully customize the management of your data network.

About the Author

Edward Spink

Edward Spink

System Analyst @ inmation