LUA is a dynamic, reflective, imperative and procedural programming language used as a general purpose scripting language.
Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo and Waldemar Celes, members of Tecgraf / PUC-RIO, the group of Technology em Computação Gráfica at the Pontifical Catholic University of Rio de Janeiro, Brazil. Versions of Lua prior to version 5.0 were released under a license similar to the zlib license. Since version 5.0 Lua has been released under MIT license. In an article published in Dr. Dobb's Journal, the creators of Lua claimed that Lisp and Scheme with their typical data structure, the list, had the greatest influence on the decision to adopt the table as the primary data structure in Lua. Lua has been used in many commercial and non-commercial applications. (Lua, s.d.)
Characteristics of language
The main features of Lua are the functions seen as first level "objects", assignable to variables, and the use of tables as generic data structures.
These particularities allow the language to implement features seen in object-oriented languages without it being the same. (Lua, s.d.)
Lua and Nios4
The choice to use Lua as a sub language for Nios4 derives from the important peculiarity of being available for all the devices of the platform, allowing to distribute and operate these subprograms on the managed operating systems.
These subprograms (script from now on) are automatically performed by Nios4 at key points of its operation, such as pre-save and post-save. Other scripts can be real commands that the user can use.
Scripts can be linked to a data table or to the program. Linked to the data, they are divided into two categories: the scripts that will be executed when the data are displayed in the tab and those that are managed within an editing grid.
Lua functions and object of Nios4have been created to be available on all devices even if, depending on the operating system, there may be different responses and operations.
An example: the reading of GPS points works on iOS and Android, while on the other systems a pair of zeros is always returned.
Another difference is related to saving any files, in fact iOS devices have a different file management than the others.
It is therefore recommended to test the scripts on all devices to avoid possible malfunctions.
Create a script
To create a new script or modify an existing one: open the appropriate page in the Options section. Remember that you need to have database administrator permissions to be able to manage scripts.
The name of the table associated with the script. If the name is ** NIOS4 it means that the script is used directly by the program.
The name of the script.
The type of script that identifies which event causes it to run
The category of permissions that can run the script
The type of device that can load and run the script.
The link to open the editor.
By pressing on Add and choosing the scope of use, all possible execution points will be displayed.
Depending on the type selected, the program may ask which table the script will be associated with.
Remember that multiple scripts can be linked to the same event in the same table and will be executed in the order they currently have in the grid.
Set the parameters to indicate who can use the script and from which device, press the Edit link to open the actual editor of the script.
The editing window is divided into 4 sections: in the left part there is the navigation bar of the functions that can be used within the subprogram, while above is the search cell where you can filter.
To insert a function, position the cursor in the text editor and click on the desired item. The values enclosed in asterisks are used to identify the parts of the function to be replaced with a real value.
At the center there is the actual editor of the script and on the right the zoom on the code.
At the bottom is the output console to be able to view the script data as it runs.
Remember that after changes you always have to save to update the script.