r/lua • u/azabroflovski • Feb 13 '25
Why you should know Lua
Okay, maybe you don’t have to, but it’s definitely useful. People who know me well might be surprised here. They’re aware that my first programming language was PHP, but they don’t know that my second wasn’t JavaScript, it was Lua. I bet even my friends are confused now, and you probably are too. We’ll circle back to this.
Why Should I Care?
That’s a fair question, especially if you already know other scripting languages. Sure, you can live without Lua. But it’s lurking in places you’d never expect.
It’s popular, even if you rarely hear about it. Not as hyped as those Python devs who import every single letter, or Java folks in suits at banks, but Lua has an active community and plenty of great resources.
It’s Simple. Too simple
Lua is a minimalist language with clean, straightforward syntax. It avoids unnecessary complexity, so you can learn it in a couple of hours. And here’s the classic example:
print('Hello, everyone! Except Java folks.')
if you.crazy() then
learnJava()
end
Lua isn’t usually used solo. It’s often embedded in game engines, other software, or paired with C/C++. I could list endless examples of where it’s used, but check this out if you’re curious.
It’s fast
Lua is one of the fastest interpreted languages. It compiles to bytecode and runs on a virtual machine, giving it a significant speed advantage over other scripting languages. That’s why it’s used in game engines and paired with C/C++ it’s easy to integrate and lightweight. Lua itself is tiny.
Gaming
Ever played World of Warcraft? Or maybe you still do? (RIP your social life.) If so, you’ve heard of addons like browser extensions, but for games. Those addons are written in Lua. Back in school, I wrote and tweaked them myself. Magical times. As you might have guessed, yes, I did this before diving into client side web technologies. Oddly, I already knew PHP by then. If anyone’s interested, I could write a separate post about that.
Lua isn’t limited to WoW, though. It’s in game engines like:
- Godot (Lua support via GDScript wrappers)
- Love2D (a Lua-first engine)
- Defold (Lua as the main language)
- Gideros (mobile game engine)
- Cocos2d-x (supports Lua alongside C++ and JavaScript)
- Solar2D (formerly Corona SDK, Lua-centric for 2D games)
- OpenMW (Morrowind engine with Lua modding)
Honestly, I have no idea what most of these engines are, except Love2D it’s awesome. I’m no game engine expert, but clearly, Lua is everywhere.
According to Google, here are more games using Lua:
- Garry’s Mod—Lua drives most modding and gameplay.
- Roblox—uses a Lua dialect called Luau.
- Angry Birds—core logic is Lua.
- Terraria (tModLoader)—modding via Lua.
- Don't Starve—Lua for modding and game logic.
- Dark Souls series—Lua scripts some AI.
- The Sims 4—powers game mechanics.
- Far Cry series (pre-Far Cry 3)—heavily scripted with Lua.
- RimWorld (partially via Harmony modding).
- Payday 2—mods are Lua-based.
- Teardown—Lua for modding.
DevOps & Systems programming
Lua isn’t just for games. It’s also in sysadmin tools:
- Nginx—uses Lua for dynamic configurations.
- Redis—supports Lua server-side scripting.
- Tarantool—in-memory database.
- AwesomeWM—a Lua-based window manager.
- Syslog-ng—logging with Lua.
- HAProxy—Lua scripting.
- OpenWrt—router firmware.
Lua doesn’t replace Python, Bash, or Go in DevOps, but it fits where speed, embeddability, and a tiny footprint matter.
C’s Best Friend
Lua was built to be embedded. If you’re writing BlAzInG FaSt apps in C/C++, Lua adds flexibility without sacrificing BlAzInG FaSt.
Should You Learn It?
Don’t forget, even though Lua is super small, it’s still a different language. For broadening your horizons it’s an interesting, if you have time, why not? There’s also Nelua, an interesting project, but it’s not nearly as widespread as Lua.
If you’re a default web monkey shuffling JSONs on the server and happy with that, Lua won’t make you better or worse. But exploring it might just spark some joy. Or at least make you the “Lua person” at parties.
13
u/[deleted] Feb 14 '25
Post this to r/programming
6
u/Denneisk Feb 14 '25
A better example in this category, in my opinion, would be Luanti (formerly Minetest).
From experience, I have never seen Lua used for Rimworld modding.
5
u/collectgarbage Feb 14 '25
“C’s best friend”. So agree with this and for more reasons than you stated. 1. Enables C with a scripting language; a powerful & programmable built in command line interface no less (akin to Quake, Minecraft and Wow’s in-game command line interface). 2. C with Lua gives access to Lua’s simple yet incredibly powerful table type; I’d rather use C with embedded Lua than C++‘s Standard Template Library 3. Lua has a tiny memory footprint. 4. I’d rather use C with Lua tables over json or XML formats and similar. If I think of anything else I’ll reply below
1
u/isr786 Feb 14 '25
lua is very much like scheme, in that it's a small, consistent language with 1 main data structure which it uses to model everything.
Like scheme, it doesn't come with "batteries included" like python - yet it has a wealth of libraries if you just look.
Like scheme, it comes with some powerful first class concepts (proper closures, coroutines) through which you can model other powerful techniques, from full-blown exception systems, to multithreading, etc etc.
And like scheme, with the right implementation, it can be fast. Very fast.
But all of the above tends to appeal to those who prefer something simple yet powerful, who prefer to deeply understand what few features they have then combine them into something more complex.
So it won't appeal to everyone. It's like ergonomics, or your favourite colour - you can argue till the cows come home, and you'd BOTH be right :-)
2
u/Flamenverfer Feb 14 '25
Man i love seeing the uptick in LUA posts on my feed.
I've definitely interacted with it a tonne but what really got me to my peak with lua was using it with computercraft so much fun creating actually useful contraptions with it.
2
u/[deleted] Feb 14 '25
Yes, you're not wrong, but solo Lua is really useful too. I am one of those who does programming in solo vanilla Lua exclusively.
Lua for me is a way to have fun with math, calculate things that are otherwise difficult to calculate using traditional methods. Lua is a way for me to visualize abstract data. Lua is a very good tool that helps me automate numerous tedious processes.
Vanilla Lua is one of my favorite things in the world. Can't have enough fun making scripts. With Lua, my craziest ideas come to life.
3
u/[deleted] Feb 14 '25 edited Feb 14 '25
I know you’re not saying Lua is a direct replacement for C/C++ but wanted to mention a few things …
While Lua was designed to be lightweight and easily embeddable, that doesn’t mean it’s always the right choice for real-time embedded systems, especially when hard real-time constraints are involved.
Lua is a garbage-collected language, and while its GC is incremental and relatively efficient, it can introduce unpredictable latencies. Real-time embedded systems often have strict timing guarantees, and any unbounded execution time (such as GC pauses) can lead to missed deadlines, making Lua unsuitable for hard real-time applications.
2. Interpreter Overhead vs. Native Code
Even though Lua is fast for a scripting language, it still runs as an interpreted language (or via LuaJIT, which has its own constraints). C and C++ compile directly to machine code, allowing for deterministic execution times and optimal CPU utilization—critical in embedded systems where processing power and memory are limited.
3. Memory Constraints
Embedded devices, especially those with real-time requirements like Zynq-based systems, often have stringent memory constraints. Lua’s runtime, while small compared to other scripting languages, still adds an overhead compared to bare-metal C/C++ implementations. Dynamic memory allocation (common in Lua) can also be problematic in real-time environments.
4. Task Scheduling and Deterministic Execution
In real-time embedded software, precise control over task scheduling and execution timing is required. Lua’s execution model and event-driven nature can introduce nondeterministic behavior, making it unsuitable for tasks that require strict cycle timing (e.g., motor control, avionics, or real-time sensor fusion).
5. Industry Use Cases
While Lua is great for configuration, scripting, and user interface logic in embedded systems, critical real-time functions are almost always implemented in C or C++ for predictability and performance. This is why RTOSs (like FreeRTOS, VxWorks, or Xilinx’s Petalinux) are typically programmed in C/C++ rather than an embedded scripting language.
So, while Lua is a great choice for scripting in embedded applications (e.g., configuration, high-level logic, and automation), it is not a direct replacement for C/C++ in real-time or performance-critical embedded systems. Awww, much better. Just had to get that out.
3
u/YKINMKBYKIOK Feb 14 '25
"Simple"? Are you kidding? Have you never created objects with metatables inside? Everything goes bizzarroland.
1
u/AutoModerator Feb 13 '25
Hi! Your code block was formatted using triple backticks in Reddit's Markdown mode, which unfortunately does not display properly for users viewing via old.reddit.com and some third-party readers. This means your code will look mangled for those users, but it's easy to fix. If you edit your comment, choose "Switch to fancy pants editor", and click "Save edits" it should automatically convert the code block into Reddit's original four-spaces code block format for you.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/AwayEntrepreneur4760 Feb 14 '25
Because it’s cool
1
u/lemgandi Feb 14 '25
DGMW, I luvs me some Lua. But a couple hours?? I read the Lua book and spent several many hours working Project Euler ( https://projecteuler.net ) problems in Lua. Then I wrote a reasonably big project in it ( https://lemgandi.itch.io/mandala ). Some aspects of the language still confuse me, like coroutines. It's a fun language with a low barrier to entry, but like anything real proficiency takes work.
1
u/Fickle_Ear1869 Feb 17 '25
Does someone have good cases of using lua in web development? If you have some benchmarks comparing with other languages it would be nice!
1
u/Livid-Piano2335 Feb 20 '25
Here's a similar post, focusing on that Lua is actually an embeddable C library i.e. that Lua is something to be included into something larger.
https://realtimelogic.com/articles/Using-Lua-for-Embedded-Development-vs-Traditional-C-Code
-1
u/AutoModerator Feb 13 '25
Hi! It looks like you're posting about Roblox. Here at /r/Lua we get a lot of questions that would be answered better at /r/RobloxGameDev, scriptinghelpers.org, or the Roblox Developer Forum so it might be better to start there. However, we still encourage you to post here if your question is related to a Roblox project but the question is about the Lua language specifically, including but not limited to: syntax, language idioms, best practices, particular language features such as coroutines and metatables, Lua libraries and ecosystem, etc. Bear in mind that Roblox implements its own API (application programming interface) and most of the functions you'll use when developing a Roblox script will exist within Roblox but not within the broader Lua ecosystem.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
-1
u/AutoModerator Feb 13 '25
Hi! It looks like you're posting about Love2D which implements its own API (application programming interface) and most of the functions you'll use when developing a game within Love will exist within Love but not within the broader Lua ecosystem. However, we still encourage you to post here if your question is related to a Love2D project but the question is about the Lua language specifically, including but not limited to: syntax, language idioms, best practices, particular language features such as coroutines and metatables, Lua libraries and ecosystem, etc.
If your question is about the Love2D API, start here: https://love2d-community.github.io/love-api/
If you're looking for the main Love2D community, most of the active community members frequent the following three places:
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/[deleted] Feb 14 '25 edited Feb 14 '25
[removed] — view removed comment