This post is a starting guide to the Lua programming language. I recently adopted Lua for one of my projects. While I had previously used Lua several years ago, I needed to get back up to speed. So, I’m sharing my reacquaintance with the language to help others.
Unlike Python or JavaScript, the Lua programming language is niche and thus tends to be used less frequently [1]. It has maintained its focus as an embedded scripting language, a role in which it excels. As a language, it is relatively simple, lightweight and efficient [2]. Historically, it was considered the fastest dynamic language, though modern JavaScript has surpassed it in the last decade [3][4]. Despite this, tight coupling with its host application can often provide a competitive advantage over other scripting languages.
Lua is used in a surprisingly wide range of programs, including web servers, games, and general applications [5]. Lapis, an OpenResty Nginx-based web server, proved to be my gateway into Lua. This framework offers particular benefits over Node.js, removing the need for an intermediate proxying stage and providing better performance [6]. The Lua ecosystem is also far smaller and subject to less change than Node.
tl;dr: In a hurry? The essential Lua links can be found at the end of the post.
The state of Lua
Lua is a mature scripting language over 30 years old and currently at version 5.4.7. It is stable, with significant releases occurring only every few years [7]. This stability can boost productivity, as you do not have to chase what others have changed. Furthermore, the widespread adoption of an independent version called LuaJIT, which offers enhanced performance, has further dampened change. LuaJIT is primarily based on the earlier 5.1 version of Lua (with some features backported from 5.2) [8]. This has effectively become the de facto version of Lua for many users.
As with other scripting languages, Lua has many third-party libraries. While fewer than for more popular languages, this tends to be less of an issue for Lua, given its embedded nature. The host project generally provides any required domain-specific support. Furthermore, there is a general package manager for Lua called LuaRocks, although it has just under 5000 packages. Compare this to JavaScript’s NPM, which may have millions but also comes with the associated security risks [9].
Lua has remained focused on its role as an embedded scripting language and continues to be a valid choice.
Installing Lua
The project you are working on may already include Lua; many of the tools I include in this post certainly do. However, having a standalone copy may still be helpful. The specifics of installing Lua will depend on your operating system.
Unix
It is relatively simple for Unix-based systems such as Linux or macOS. You can use a package manager such as apt, yum, or brew (for macOS) to install Lua.
So, for example, on the Mac, you would type the following:
brew install lua
brew install luarocks
On the Mac, you really need the Homebrew package manager for any serious development work. It can be found here, along with details on how to use it.
Windows
Unfortunately, installing Lua on Windows is more problematic and may require manual intervention and user knowledge. How you go about this will depend on your existing development environment. Are you using Visual Studio or an open-source compiler such as MinGW or MSYS2 for better Linux compatibility?
Here are a few guides that will provide details on installing Lua for Windows.
- Installing Lua on Windows (A simple installation of just Lua)
- Installing LuaRocks on Windows (Installing LuaRocks, the package manager that includes Lua and can support either MingGW or VisualStudio, depending on your setup)
- Installing Lua, MinGW and LuaRocks on Windows (A more opinionated install with MingGW)
Learning Lua
Lua is a relatively simple language for anyone with some programming experience. However, it can feel anachronistic, especially with its verbose block structure using ‘end’ statements, loop counting starting from 1 and its lack of more ‘modern’ features [10]. While one becomes accustomed to these aspects, I recommend using something other than Lua if you are new to programming. For example, Python might be a better choice as a first language.
An overview
You can start acquainting yourself with Lua by visiting Learning Lua in Y Minutes, which provides a comprehensive overview of the language, giving you a sense of what to expect.
Leading from this would be the concise five-part tutorial on Lua for Programmers by Michael Ebens:
- Part 1: Language Essentials
- Part 2: Data and Standard Libraries
- Part 3: More Advanced Concepts
- Part 4: Tips and Tricks
- Lua Metatables Tutorial
These offer a great introduction to some of the essential elements of Lua.
The Lua books
A couple of books stand out as essential for learning Lua. They were written by the people who created it. This is the core of learning the language, and depending on your experience, it may take several days to work through. It is worth the effort, as you will be left with a solid understanding of the language.
Programming In Lua
This is the official guide to programming in Lua and remains one of the main sources for learning the language. It is where you will spend most of your time coming to grips with it. Several versions are available; you can buy a copy or read the older version online for free.
- The current 4th print edition is available on Amazon, covering Lua 5.3
- The first edition is available online for free, covering Lua 5.0
- A complete list of the editions can be found here.
If you are focusing on using LuaJIT, you might consider purchasing one of the intermediate editions.
Lua 5.1 Reference Manual
This is the main reference book for Lua, where you can learn the finer points. It will be an invaluable resource as you start to use specific parts of the language when you begin programming with Lua.
- The print version is available on Amazon.
- It is also available for free online.
Using Lua
The final stage in learning is using the language itself. Lua is straightforward, making it easy to understand. Its relatively small size makes it more likely that you will encounter all its parts quickly, unlike more complex languages such as modern C++ or Python.
Lua Resources
As with all languages, once you are up to speed, you will need to find the resources and tools to help solve whatever problem you are working on.
Standard Library
Lua comes complete with a standard library providing the usual functionality one might expect. The Lua Reference book provides a chapter covering this in more detail. To give you an idea, for Lua 5.1, the standard library included the following modules:
- A basic library.
- A coroutine library.
- A package library.
- String manipulation.
- Basic UTF-8 support.
- Table manipulation.
- Mathematical functions.
- Input and output.
- Operating system support.
- Debug functionality.
Third-party Lua
Moving beyond this basic functionality, you will inevitably need some form of third-party library to provide specific features unless you plan to develop them in-house or if they come as part of the project you are working on.
As I mentioned earlier, Lua’s de facto package manager is LuaRocks. It provides a command-line tool that you can use to install packages. Looking beyond this, many sites provide lists of resources that may be useful to a Lua developer and are great places to explore what is available in Lua. Two of the better ones I found are:
- Awsome Lua – An extensive collection of Lua links.
- LuaAddons – A comprehensive list of Lua links by the community.
There are some dead links, especially for LuaAddons.
IDE Support
Working with Lua requires an IDE or editor. One of the best current options is ZeroBrane Studio, a lightweight, cross-platform editor for Lua, written in Lua itself.
If you want a more mainstream solution, try Visual Studio Code with the “lua-language-server” extension, the most popular option offering language support for Lua.
If you use one of the JetBrains IDEs, at least one plugin is available.
Use Cases
Lua has been used in many applications, games and programming tasks [11]. This final section will consider a few of these areas and the available solutions in Lua. Rather than being comprehensive, it represents my opinion on the most interesting examples.
Web Development
Lua provides several robust solutions for running websites and microservices. A solid platform underpinning your site is crucial when creating a dynamic website or application. Webdev is undoubtedly the reason I have returned to Lua. After using Node.js, I recently sought an alternative solution and will move to Lapis (based on OpenResty).
This may be a future post in itself.
OpenResty
OpenResty is a web platform based on Nginx and LuaJIT that allows you to create web applications. It is similar in concept to Node.js but has the benefit of being directly integrated into the web server. This tighter coupling results in greater performance, as reflected in the benchmarks I have seen [12].
The awesome-resty page hosted on GitHub is an excellent place to look for further information.
Lapis
Lapis takes OpenResty and creates a web server platform with batteries included. It provides all the backend functionality needed to create an out-of-the-box website, trading some performance for flexibility. The creator of Itch.io has made it to run their website, suggesting a certain level of reliability.
Redbean
Redbean is an alternative web server solution for Lua. It provides built-in server functionality and the ability to deploy a single file, which is attractive for microservices. It comes as a single executable into which you can embed your files. While it is less fully featured than OpenRusty, it offers an interesting solution.
Game Development
Lua was once considered one of the premier game scripting solutions. Many popular games still use it for scripting, the most famous of which is World of Warcraft for its UI system. However, in recent years, it may have been superseded by other scripting languages. For example, the Godot engine has implemented a Python-like language rather than Lua [13]. Despite this, good options remain available for developing games with Lua.
Defold
Defold is a free, fully featured cross-platform game engine emphasising 2D games [14]. Beginning life as a side project, King acquired it in 2014 before it became independent in 2020 under the Defold Foundation. It has been developed professionally throughout its life, which stands out compared to similar free offerings. Its philosophy is to provide a solid low-level base for building games, allowing the freedom to create almost anything. This gives developers greater control but may require more work [15].
Awesome-defold maintains a list of links related to Defold.
Love2D
Love2D is a popular choice for Lua game development. Unlike Defold, it is more of a game framework than a fully-fledged game engine. It is also extensively cross-platform and popular for game jams [16]. It is fully open source and has been in development since 2008.
Application Development
Lua can also be used for general application development. When discussing IDEs, I mentioned ZeroBrane Studio, a standalone application that is a good example of an application entirely written in Lua. While it tends to be used only sparingly in general application development, this is a shame, as Lua is well suited to the task.
Regarding UI libraries, wxLua is the most complete interface library I have found for Lua. It is based on the wxWidgets cross-platform GUI library and an old C++ library [17]. However, learning to use wxLua will require some effort; it is an extensive library on par with the Qt library or Microsoft MFC.
Other options are available, but they are generally experimental, incomplete, or abandoned.
If I find something easier to use, I will update this section.
Final Thoughts
In this blog post, I have tried to guide you in starting with the Lua programming language for 2025. In fact, given that Lua changes only a little over time, this guide should be valid throughout the 2020s. Stability is one of the factors that has attracted me to Lua. In the past, I have considered the popularity of programming languages to be an important factor in their selection, especially for this blog. I explained this in an earlier post discussing which language is the most widely known. With the advent of AI, I no longer think this is as important; instead, my productivity comes first. So, expect more Lua on my pages moving forward.
Lua is a capable language that excels at its task as an embedded scripting language. It is as relevant today as it has ever been. However, it is also relatively niche; many developers may never need to use it. If you do, this guide is for you.
Further Reading
The most important resources and links for starting with Lua from the post :
Learning
- The website Learning X in Y Minutes (for Lua).
- The Lua for Programmers tutorial series.
- The online book Programming in Lua (Lua 5.0).
- The online book The Lua Reference Manual (Lua 5.1).
- The online book Lua Programming Gems.
Resources
- Awesome Lua a place for active Lua links.
- LuaAddons is a community list of links.
Tools & Libraries
- Zeobrane Studio a native Lua IDE
- Visual Studio extension for Lua
- OpenResty, the web application server for Lua.
- Defold a cross-platform game engine supporting Lua.
- wxLua a cross-platform GUI for Lua
Notice
The header image was AI-generated by Microsoft Image Creator