How is Lua used in embedded systems

Lua: Use of Lua in embedded systems

Not only known after Stuxnet, Duqu and Flame or from World of Warcraft

ISBN 978-3-907857-15-1, 188 pages, paperback, € 19.80, Lua (Portuguese for moon) is a scripting language that can be integrated into programs to make them easier to develop and maintain. One of the special features of Lua is the small size of the compiled script interpreter. Lua programs are translated into bytecode before execution.

Although Lua can also be used to write standalone programs, Lua is primarily designed as a scripting language for C programs. The Lua interpreter can be addressed via a C library, which also contains an API for the runtime environment of the interpreter for calls from the C program. Using the API, different parts of the program can be written in C and Lua, while variables and functions remain accessible in both directions (i.e. a function in Lua can call a function in C and vice versa). Lua is implemented in ANSI-C and supports both functional and object-oriented programming.

Since the Lua interpreter is extremely fast and highly portable and can be easily embedded in C programs, it is an attractive alternative to other script interpreters, especially for embedded systems. Although it is only a few kilobytes in size, a full garbage collection still fits into it, which automatically throws the accumulated garbage out of the memory.

With this brochure, the authors want to use their experiences to clarify the features of Lua and to demonstrate the expandability with several examples.

In the first example, the Lua interpreter is expanded on a PC with a DLL that enables the control of an AD-DA subsystem connected via USB.

In a second example, Lua is embedded in an application on an embedded DOS system based on an Intel386 ™ EX processor with ROM-DOS (compatible with MS-DOS 6.22) and shows that Lua can also be used in systems with scarce resources.

In the third example, the DOS application is replaced by a Linux application using the compact FOX Board G20, a Linux embedded single board computer based on an Atmel AT91SAM9G20 microcontroller.

The application examples conclude with eLua, a Lua adapted for microcontroller applications. An mbed microcontroller module based on a Cortex-M3 is used here.

In the last section, tools with SWIG and ToLua are introduced which, under certain conditions, can simplify the link between Lua and C / C ++.

All source texts are stored under SourceForge. There is also a website for the book.