Lua Scripting Language
CadnaA includes the scripting language Lua to automatize tasks and parts of established CadnaA workflows. Lua is a highly regarded scripting language which is famed for execution speed and ease of use. CadnaA-Lua enables to access:
- attributes of CadnaA objects (using the known identifiers),
- memo text variables,
- vertices of polygons (polygon points),
- looping constructs to perform operations on sets objects.
This chapter provides a introduction to the Lua scripting language, including examples showing how to use CadnaA-Lua when accessing CadnaA objects. A reference section lists all functions and objects.
Hinweis
CadnaA uses Lua version 5.4.8. Additionally, following math functions from earlier releases are also available: math.atan2(), math.cosh(), math.sinh(), math.tanh(), math.pow(), math.frexp(), math.ldexp(), math.log10(). For more information, see www.lua.org/manual/5.4/.
CadnaA-Lua provides the power to access CadnaA‘s objects and functions using a simple yet powerful and fast extension interface. With CadnaA-Lua, the user can automatize frequently employed work flows and supplement powerful dialogs like ObjectScan and Modify Objects. Lua is an accessible scripting language that is popular with a broad user-base and offers a comfortable experience for experts and users alike.
Requirements & Support
Basic programming knowledge is required in order to use Lua scripting properly. Please consider that the CadnaA maintenance contract does not cover the development or the debugging of Lua scripts. In case you need further assistance please contact DataKustik to receive an offer for this kind of service.
Lua Editor
The Lua interpreter is embedded into CadnaA, yet Lua scripts should be written outside of CadnaA using a suitable editor or programming environment with ‘syntax highlighting’. “Notepad++” would be an example of a suitable editor (http://notepad-plus-plus.org/). There is no need to install an external Lua environment since Lua is built-in into CadnaA.
Loading and running Lua scripts
CadnaA Lua scripts are loaded and started via the command/dialog Execute Scripts on the Extras menu.

Dialog Execute Scripts (on Extras menu)
Loading a Lua script
Click the file selector symbol
to load a Lua script.
Starting a Lua script
Click the "Run!" button to start the loaded Lua script.
Using external libraries
External Lua libraries provided as .dll and compatible with Lua 5.4 can be placed in the subdirectory /lua_libs in the installation directory and imported afterward.
The following libraries are included by default in the CadnaA installation. To use them in a Lua script, they must be imported at the beginning of the Lua file:
local sqlite3 = require('lsqlite3')
local iuplua = package.loadlib('iuplua54.dll', 'luaopen_iuplua') or error('Failed to load iuplua54.dll')
iuplua()
Display of Results
In case the script generates any output the data is displayed on this dialog.
Note
Lua scripts can also be started via the toolbar (see Edit Toolbar).
LUA-Scripts presets
The Lua-Scripts Presets command on the Extras menu runs predefined LUA scripts without requiring to select and to launch them via the Execute Lua-Scripts dialog.
On program startup, CadnaA scans whether there is a folder lua_presets in the install directory and/or in the directory where the file CADNAA.INI resists. If so, all *.lua files found are listed in the Extras|Lua-Script Presets menu. To run a script, select the name of the LUA script from the sub-menu.
You may copy your own scripts to this folder. The files with the file extension *.luax contain CadnaA specific scripts that can neither be opened, nor be edited by the user.
The name displayed on the menu is the filename unless the script‘s file contains a comment in its first line (starting with „--“, i.e. double hyphens) with the keyword #NAME(„xxx“). In this case, xxx is displayed.
Following lua scriptes are included:
- Transfer attributes
- Find intersections of contour lines
Opening the LUA command file
If you select Open Lua Command File on the Extras menu, the file cnacmd.lua is opened.
For further details see Action „Lua Command“.
Opening the LUA event file
There is no specific menu entry in the at Extras for opening the Lua events file, but you can use the menu entry Open Lua Command File while using the SHIFT key. With this, the file cnaevent.lua is opened.
For further details see Action „Lua Event“.