Lua Server Pages

Why Use Lua in Embedded Systems?

There are many reasons to choose Lua in embedded systems. For one, Lua is a high-level language, similar to Python, and super easy to learn. With Lua you avoid many of the problems associated with the C/C++ programming languages that dominate embedded systems, such as buffer overflows, memory leaks, and other memory corruption errors. And this is particularly a problem in larger projects where many computer programmers with varying skills are involved.

A benefit of Lua is that it abstracts out the details for the underlying microcontroller hardware. Instead of worrying about the bits and the bytes, a developer simply accesses methods of a peripheral object to control the hardware. Hardware control is done via a so called Lua binding. The abstraction of the hardware layer allows developers to focus on the application specifics rather than on the workings of the low-lying hardware.

Lua Server Pages (LSP) extends Lua with additional features, such as IoT, making it very easy for any developer regardless of experience to safely design network/protocol related functionality and high level logic in Lua.

Lua is the only module in the Barracuda Application Server not developed by Real Time Logic. Lua is licensed under the terms of the MIT license and can therefore be used in any commercial product without any restrictions. See the Lua license for more information.

Learn How To Use Lua In Embedded Systems

If you are an embedded C or C++ developer you will find learning Lua very easy. Lua is a beginner-friendly coding language and, for this reason, used in many frameworks. For example, Roblox promotes the user friendliness of Lua as a first language for children. If a child can learn Lua, so can your team members. An added benefit of Lua is that a high level language enables non hard core C/C++ developers to safely work with embedded system programming.

New to Lua?

Get a quick introduction to Lua by following our Online Interactive Lua Tutorials

Is Lua too slow for resource constrained devices?

A criticism that we often hear is that Lua will be too slow for embedded use. Nothing could be further from the truth since Lua is both super compact and blazingly fast. We urge you to contact us for a friendly chat if you have any concerns about using Lua as part of your design.

Is Lua difficult to integrate in embedded systems?

The Barracuda App Server and the Lua C libraries are easy to compile and link with the rest of your embedded software (firmware). We provide an optional amalgamated version that consists of one C file that you may drop into any IDE or add to any Makefile.

Python vs. Lua

Python may be the king of the desktop, but Lua rocks in embedded systems. Python's main focus is to be a generic and easy to use command line scripting language, while Lua is designed to be a C Library with its main focus on being easy to integrate into a larger program. Lua is found in many games such as World of Warcraft. Lua has traditionally been selected when speed and size matters. Developers generally find Lua to be much faster and less resource hungry than Python. A developer that knows Python will find it easy to learn Lua since both languages are similar.

Barracuda App Server adds the missing IoT batteries

Since Lua's main focus is to be embedded into a program/firmware, one of the criticisms you will find of Lua on the Internet is the lack of Lua batteries, referring to the lack of general libraries. What the Barracuda App Server does is to bring these missing "batteries" to Lua and makes it possible to use these batteries in deep embedded RTOS devices.

How to Use Lua Efficiently

One of the great benefits we have learned from the Lua founders is simply, "Use Lua for what it is good at". Lua developers in general do not try to solve everything using Lua. We believe this design pattern is the main reason for why Lua has been so successful in the gaming Industry, where Lua is used extensively. Modern embedded systems have a tendency to be very complicated, especially when IoT and cloud connectivity is added. These non real time components are much easier and safer to design in a high level language, especially when the development framework comes with IoT support. With the Barracuda App Server, a C coder can do all the real time components in C code and use Lua to control these C components.

Lua Debugger Screenshot

The Lua debugger makes it easy to develop and test Lua in embedded systems

Using LSP for both Embedded Code and Web Applications

Lua Server Pages (LSP) was initially designed for server side web development, but now provides much broader support for embedded and network related programming. We have seen from our customers that up to 80% of a modern embedded system can successfully be implemented using LSP, ensuring dramatically reduced development time and cost.

Please see the article Lua fast-tracks embedded web application development if you want to learn more about how LSP can be used for web development and the article What is an Embedded Application Server for an explanation on the difference between a web server and app server.

Using Lua as a General Purpose Programming Language for Firmware Design

Check out the hands-on article Embedded Programming Using Lua. This article shows how to build IoT firmware without having to write any C code.

Embedded Programming for Non C Coders

Download the Barracuda App Server for RTOS or Linux Now!

Are you using an RTOS? If so, why not purchase a $10 ESP32 and try our ready to use Barracuda App Server library for ESP32. A complete ready to use FreeRTOS/lwIP example can be downloaded from GitHub.

Embedded Linux users can download our Mako Server. We provide ready to run binaries for many embedded platforms.

Customers Discover the Benefits of Lua Server Pages

We have customers using the Lua Server Pages plug-in in everything from deeply embedded monolithic systems, such as in Xilinx FPGAs, to high-level host systems, including Linux and Windows. The Lua virtual machine can be compiled for any microprocessor architecture, including CPUs embedded inside FPGAs such as an 80MHz ARM processor that is sufficient to run the Lua virtual machine. The web page you are reading now is managed by Lua Server Pages.

Customer Testimonial:

"It was great that you drove the point across regarding the benefits of using Lua. I think that most embedded people, such as myself, would initially gravitate towards C code and CSP because it's a familiar environment and disregard Lua without realizing the huge benefits that can be gained with only a little bit of an upfront cost of having to learn the Lua language. BTW, you definitely made us think about Lua a whole lot more and not just as a server-side scripting language but as a scripting language that we could potentially use throughout our entire project." - Honeywell employee attending our three day training.