If you like Lua, see Terra, https://terralang.org/
> Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.. Like C/C++, Terra is a statically-typed, compiled language with manual memory management. But unlike C/C++, it is designed from the beginning to be meta-programmed from Lua.. In Terra, we just gave in to the trend of making the meta-language of C/C++ more powerful and replaced it with a real programming language, Lua.. Terra programs use the same LLVM backend that Apple uses for its C compilers. This means that Terra code performs similarly to equivalent C code.
From Pat Hanrahan's research group at Stanford, https://amturing.acm.org/award_winners/hanrahan_4652251.cfm
Hanrahan and his students developed Brook, a language for GPUs that eventually led to NVIDIA’s CUDA. The prevalence and variety of shading languages ultimately required the GPU hardware designers to develop more flexible architectures. These architectures, in turn, allowed the GPUs to be used in a variety of computing contexts, including running algorithms for high performance computing applications, and training machine learning algorithms on massive datasets for artificial intelligence applications.
Papers: https://terralang.org/publications.htmlHaving just gone through the exercise of integrating Lua with a custom game engine over the past few weeks, I have to echo how clean the integration with other languages is.
It's also worth noting that the interface is clean in such a way that it is straightforward to automatically generate bindings. In my case, I used a handful of Roslyn Incremental Source Generators to automatically generate bindings between C# and Lua that matched my overall architecture. It was not at all difficult because of the way the interface is designed. The Lua stack together with its dynamic typing and "tables" made it very easy to generate marshallers for arbitrary data classes between C# and Lua.
That said, there are plenty of valid criticisms of the language itself (sorry, not to nitpick, but I am really not a fan of one-based indexing). I'm thinking about designing an embedded scripting language that addresses some of these issues while having a similar interface for integration... Would make for a fun side project one of these days.
I can't say I appreciate Lua any more after reading this. It only reinforced my annoyances with it.
It's been a while since I wrote any Lua but I didn't think it was intuitive at all. Why are arrays tables, why are they nil terminated and why do they start at 1.
I don't think it's underrated either. It's very popular for writing scripts in (older) game engines.
I built a chatbot with lua plugin commands and I really had an awful experience trying to incorporate it in my C++ program. I really don't understand why people say it's easy to embed because you have to do a ton of stack manipulation to do anything. Not only that but the language itself is cumbersome, frustrating, and does nothing at all to help you when you make a mistake.
I will never use lua again and avoid any project that uses it.
It's hard to use lua for any sizeable chunk of code due to weak typing, absence of type hints and error handling. No it's not underrated in any way.
It's funny how through the years I've started to appreciate statically typed languages and type hints (Python, TypeScript) as well. Up to my current stance: it's a disservice for a community to write hintless python or js code.
P.S. Recently I've rewritten 1.5k cloc of JS into TypeScript. As usual there were dozens of cases of missed nulls, null attribute accesses or semantically questionable nulls.
I have really enjoyed working with Lua when it's come up and I think it's an extremely good language. In particular, as Noë says, its interface for embedding into C/C++ is clean and flexible. There are performance concerns, but considering how widely Lua is used for game logic in high performance video games clearly those concerns can be addressed.
That said, I think there are other warts that can be confusing and make the language difficult. The Nil-Terminated Arrays section points out one oddity about `nil` - but there are many others. There are a number of confusing corner cases (or were - I haven't used it in a while). As an example, if you have a list of values and you pass that list into a new table, the resulting table may be different than if you add each value in that list in order.
I also think that the flexibility of embedding means that you are often learning the Lua <=> C interface as much as you are learning Lua. So jumping from deploy to deploy is more confusing than most languages.
Nevertheless I fully agree the language is underrated!
My humble opinion is that most applications that need scripting should just embed JavaScript.
It has a massive advantage in the existing ecosystem. People don’t always love it, but millions of them already know it. You don’t need to re-learn array indexing and nil termination quirks and the dozens of other things where Lua is subtly different in ways that you’ll find out at runtime.
There are JS engines in all sizes, from tiny interpreters to world-leading JIT performance monsters. And most operating systems nowadays ship with a high-quality engine and embedding framework that you can access without installing anything, like JavaScriptCore on the Apple platforms.
Do your users a favor and just use the boring standard language instead of making them learn a completely new one that doesn’t offer meaningful practical benefits for them. It’s probably not as much fun for you, but you’ll save time for both the users and yourself in the end.
Luau [1] developed by Roblox is a backwards-compatible fork of Lua 5.1 with some very significant improvements to speed and QoL [2]. It also mostly alleviates the nil-terminated array problem.
I've had fun embedding Lua a couple times, but as with wasm I almost never have a case where I need to run new code without being able to recompile the whole binary, so I don't get to use it often.
The most fun was when I made a game engine ("engine") in C++ that used Lua for all the game logic. The fast debug cycles are very useful there. Maybe I should still do that for Rust gamedev, since Rust notoriously compiles slowly.
The second-most fun was an IRC bot that could reload its Lua logic without disconnecting. Nowadays I'd write a bouncer and just let the main process restart. (Or use wasm, a wasm IRC bot would be good...)
The third-most fun was using Lua as a Turing-complete configuration language. If I needed an array of something, I just made Lua make an array, instead of generating Lua code.
One of the least fun was the Blender plugin that exported 3D models as generated Lua. If I did that one again today, I'd just use MsgPack or some ad-hoc binary format.
Lisa is deeply, deeply overrated, ime. But I'm coming from the games industry where it's widely used.
The only benefit of Lua ime is the ease at which it embeds in C++. Beyond that, it's a nightmare.
I think it's a stretch to call it underrated. Isn't it the defacto language for embedded scripting stuff? I've seen it used as a mini language in production in game engines, databases, and trading systems.
On the other hand, if the article is saying that it deserves to be more highly rated in the non-embedded space, I think I would need more than a handful of syntactical niceties to explain why it deserves to be in the same conversation as Python, Ruby, etc...
Except for "tables". Lua tables are too weird. Trying to make one construct do the work of an array, a struct, and a dict leads to a messy construct.
There are a lot of good comments here already, but I can't let this pass by the main page without taking the opportunity to rail against Lua because, no, it's not underrated. It's everywhere and terrible.
This article is fairly light on detail, only mentioning a couple table footguns, but there are MANY more. (I also disagree with it being "accessible even for beginners", but I'll stick to objective things.) For starters, the size operator `#` doesn't work on map-like tables, and there's no easy way to copy part or all of a table, or to serialise one for printing.
Lua doesn't have `switch` or even `break`/`continue`. Though it added a `goto`—years after we collectively realised that's an antifeature. You can use `and`+`or` as a ternary, but you need to remember that it works differently with bools and that `nil` is falsey ofc. And `0` is truthy. Using a variable which hasn't been declared yet or is otherwise out of scope gives `nil` rather than an error. In fact most logic errors are SILENT (yay dynamic typing), and some syntax errors are raised far from the actual cause. `<const>` isn't.
Before Lua 5.3, all numbers were floats. The patterns used for `string.match` look superficially like RegEx but they are not, despite them predating Lua. The stdlib is woefully lacking, with the official documentation seeming to taunt you with examples of how several common functions could be implemented, but it's left to you to copy them into your projects.
So yeah, Lua might be small and quaint, but that's only because so much is not included "in the box", and what is included is no good.
Mandatory plug for Redbean[0], a standalone Lua webserver (a single-file that runs natively on six OSes!), and Fullmoon[1], a web framework built on top of it.
Not exactly mainstream, but so simple and elegant.
Lua fits the same niche as Tcl, but the runtime is smaller and way better. Tcl started as a simple, embeddable scripting language (and low performance, it was just string substitutions!) and evolved into Tcl8, a mostly backward compatible object system after successive iterations to improve its performance and expressiveness. "everything is a table" gets you pretty far in Lua, in much the same way that "everything is a list" in lisp, and was a much better abstraction than Tcl's "everything is a string."
When I last used Lua professionally (10 years ago) I did discover some foot-guns related to the handling of NULL / nil in the LuaSQL module. The Lua array length function was based on nil-termination, so a NULL value in a column could cause issues. Maybe this has been fixed by now?
Lua as a language is pretty warty, with some obvious omissions. But it’s widespread as an embedded language, and has been around a long time, and I think that tends to give it a nostalgic halo effect.
I would like to see more minimalist scripting languages with modern sensibilities replace it.
Add, no way to determine size of Array, which is the primary data structure anyway.
No item.length propery.
You might decide to count with foreach(), but that will terminate when it encounters the first value in the array that is NULL.
Really liked that post, then again Lua is one of my favourite languages.
I wrote this post https://andregarzia.com/2021/01/lua-a-misunderstood-language... some time ago and it kinda touches similar points as the OP. Read on if any of yous want to see yet another person talking about Lua.
especially with fennel on top, i can certainly see the uses and appeal!
coming from mostly python, i miss a robust stdlib.
I used Lua the first time in Garry's mod, and I had a absolute blast, was my first real programming language, I can vouch, it's easy to pick up :) I also must admit, the gmod lua extension (glua) was so much more enjoyable, that since then I keep my own lua version with patched ! for not and != as alternative for ~= (Luas way for not equal)
I love Lua as a language; even if it can be a bit cumbersome at times, its simplicity and low barrier of entry is refreshing. I'm currently building a full-stack web application with https://redbean.dev in Lua and it's mostly been a joy.
I've been writing lots of lua recently. The only two things that bother me are indexes starting at 1. It's made my 2d grid math more complicated. I also don't like how I have to write a goto statement if I want to continue/next inside a loop. Other than that I love the simplicity.
Lua is a great language for extending systems and very high-level scripting. I like it. I had the pleasure of teaching a module in 2020 together with Roberto Ierusalimschy where we used Lua and LPeg to teach students how to write a simple programming language. It was a very fun class.
In the Spring/Recoil RTS game engine[1] we adapted Lua to have deterministic execution allowing synchronous multiplayer simulation. In addition we relatively easily implemented a precise[2] serialization of the Lua VM, allowing us to support save/load for games with no code required from their side.
In other languages these would require much more effort.
[1] https://github.com/spring/spring or https://github.com/beyond-all-reason/spring (yay for forks!)
[2] Preserving the order of iteration on items in a hash table after deserialization and further manipulations.
If you like how easy is to embed Lua but not liking it's syntax or features you can try FixScript.
It's a language I've created that has C-like syntax, the implementation is a single .c file. It's unique feature is an ability to arbitrarily extend the syntax (in fact classes and the type system is implemented as a library). This can be used for specific needs of your project.
It has also an ability to have time limits for execution and is able to reload scripts in place for live code updates. It also has a JIT by default.
More information here: https://www.fixscript.org/blog/introduction
> Lua is used in nvim for plugins since 0.5.0, you bet it's efficient !
Not necessarily, plenty of editors have scripting options that aren't going to win any performance price.
Also VI architecture goes back to the days of single digit MHz.
I guess one of the issues is that because Lua is tailored for embedded use case, it lacks appeal as a general purpose software development ecosystem and thus its usage is marginal.
I took Roberto's awesome "Building a Programming Language" course in 2022 and during a live class I had the opportunity to ask why they don't incorporate more stuff into the language. He said that it was designed to be lightweight, effective and simple. Anything that goes against those principles should not be integrated into Lua's codebase.
Lua as a language is underrated, yes. Lua as the implementatation of PUC Rio is what it is. It misses abstractions in the runtime to make it pre-emptive and parallel. It is also somewhat telling that Mike Pall despite his come back announcement didn't deliver.
It comes with batteries but they only fitt into one brand well. Compare this to eg golang or Python.
The best way to use Lia is using Typescript - https://typescripttolua.github.io/
We have huge Lia codebase for game client and game server shared code all written in typescript. Our developers only see lua if something does not work and it’s not often.
Lua can be used to access the NetBSD kernel, which is interesting. I have said it before, I should spend time learning Lua.
Is Lua currently even faster than JS and PHP, after all the effort that went into those languages’ optimizations?
I recently came across TypescriptToLua[0] which has improved my experience of writing Lua manyfolds. No more having to deal with 1-based indexes or lack of type hints.
It looks like Lua's conditionals, for loops, and function definitions terminate with the "end" keyword. Is this considered more readable or does it bring some other benefits besides helping the interpreter parse code?
Many people love Lua, so I suspect there is a good reason for this.
Indexes should start at one in all languages IMO.
The zero thing is a historical quirk due to pointer arithmetic.
Lua is nice but it being embedded in many different places means that there will often be environment specific context that's injected for you to interact with, but any editor tooling won't know what's injected
The article doesn't mention some of the most famous Lua cases out there: Roblox used it for game developers, HAProxy uses it for extending the LB, and others.
Maybe it's time to check out Luon [1], which has a syntax similar to Oberon and takes some concepts from Lua, it's statically typed and targets the LuaJIT VM. It was recently covered in HN [2]
[1] https://github.com/rochus-keller/Luon/blob/master/Readme.md [2] https://news.ycombinator.com/item?id=42413343
My complaints with Lua are mostly superficial, but they irk me nonetheless. So if I have to use it, I'll usually opt for Fennel.
I wonder how viable is Lua for a full stack application or webpage.
It has a very barebones standard library by design
I started using Lua for Cyberpunk 2077 mods and neovim configuration, it's fun to use.
Scripting language with the worst syntax I've seen so far.
I like Lua. It's a saner version of JS with much fewer warts. However, JS has a massive, enormous, insurmountable advantage in popularity. If I need an embeddable scripting engine in 2025, I will most likely go with JS.
Doesn’t lua use 1 indexed arrays? Breaks my brain.
i wish luajit has been actively evolving though
> The one that bothers me the most, might be the fact that arrays (tables used as arrays) are nil-terminated, meaning the end of the array is marked by a nil value
This alone should underrate the language even more so that no poor user is exposed to this kind of nonsense
Until its array start from 1.
I feel Scala is also very underrated.
The 1-based indexing feels too icky to me. It was a language designed for non-programmers and it shows, imo.
I feel like, except for small size, this post doesn't really get into what I like about Lua, which is pretty unfortunate. Lua deserves a better case than this.
I'm maybe not the best person to write this because I'm not really a huge Lua fan. Though on projects with others I'll use whatever language they're using, left to my own devices, I probably write about 3Ă— as much JS as Lua, about 32Ă— as much Python as Lua, and about 20Ă— as much C as Lua.
But Lua has some really nice attributes.
It's a pretty reasonable very-high-level language comparable to Python, JS, Groovy, Perl, or Clojure. You can get a lot done in very little code. You don't have to crank out piles of boilerplate the way you do in Java or sometimes C. It comes with concise and readable syntax, flexible data structures, garbage collection, strong dynamic typing, list structure, hashmaps, dynamic method dispatch, inheritance, operator overloading, cooperative multithreading, eval, exception handling, namespaces, closures with lexical scoping, etc. Its documentation is first-class. Most of this is pretty much standard for the dynamic-language category nowadays; there's not much special in here to pick one language from the category over another.
Lua's biggest advantage is that LuaJIT is motherfucking alien technology from the future. I wrote a straightforward escape-time fractal renderer in https://gitlab.com/kragen/bubbleos/-/blob/master/yeso/mand.l... with a dynamic function invocation in the inner loop (to switch between fractals) and LuaJIT's trace compilation just compiles that right out. There's also a real-time animated raymarcher in that directory in LuaJIT, though the framerate and resolution are pretty bad. You can literally just write high-level code at like a Python or JavaScript level and, as often as not, it just goes faster than C. (Sometimes it doesn't. JIT compilers are unpredictable and sometimes disappointing.)
Now, probably somebody is going to reply to this and tell me that everybody runs JS in JIT compilers too, so this isn't a real difference. Unfortunately that's horseshit. I'm sorry, but V8 and SpiderMonkey are just not in the same league, though not because their implementors are less brilliant. They're just attempting a much harder job, because JS is a much hairier language. Consequently their performance is an order of magnitude worse.
(Even regular non-JIT Lua is a lot faster than most other very-high-level languages, almost to the level of JS JIT compilers.)
LuaJIT's C FFI is also just ... there's no expression in English sufficiently emphatic to express how great it is. The expression I'd normally use translates literally as "it's a very child of ten thousand whores," which hopefully conveys some of the emphasis if not the content. Here's the FFI binding for Yeso, the graphics library used for the above fractal demo: https://gitlab.com/kragen/bubbleos/-/blob/master/yeso/yeso.l.... Yeah, just by pasting the relevant lines from a C header file into your Lua program, you can call C code from a shared library as if it were Lua code. It's almost as easy as calling C code from C++!
After getting screwed over (along with everybody else) by the Python community's gratuitous and ongoing breakage of backward compatibility, coupled with public shaming to persuade more people to break backward compatibility, the Lua community's approach to backward compatibility is looking pretty appealing. The vibe is that old versions of the language live forever, and you should keep using them instead of upgrading, but new versions usually aren't compatible. However, it's much easier to make a Lua library compatible with every existing version of Lua 4 and Lua 5 than to make a Python library compatible with any version of both Python 2 and Python 3.
Being small, fast, and implemented purely in portable standard C makes it practical to run Lua even on larger microcontrollers like the ESP8266, even when they use weird CPU architectures. Even interactively. https://github.com/nodemcu/nodemcu-firmware
LuaJIT is much less portable than PUC Lua, and also more than twice the size, about 580kB on my machine. This is still orders of magnitude less than something like Python or the JRE.
Lua is a little more annoying than Python or node.js to develop interactively with, but it's overall pretty comparable. For code I'm writing myself (as opposed to getting from a library) the Lua version usually ends up being just a little bit bigger than the Python or JS version. Lua is more bug-prone, though, due to a number of language design flaws.
Lua is a very newbie-friendly language, I think even more so than JS or current Python. It's very successful in systems aimed at beginning programmers, like Minetest (Luanti), World of Warcraft, and LĂ–VE2D. The barrier to entry is very low; you don't have to be learning the GUI of a new IDE at the same time that you're learning the programming language and, possibly, how to program. The standard library is small rather than overwhelming. And the download for standalone Lua development is tiny.
Did they ever fix the 1-index thing?
No transparent parallelism? And no, I don't mean threads.
Underrated? Eh... it does stuff better than others but that doesn't mean much.
We really don't learn.
Lua is not underrated. It’s how many now, still 4(?) different languages which continue to suicide after a few years, all with cringe [re]design decisions, half-assed mechanics and lack of convenience that authors refuse to address. I spent many years on it (embedding, metaprogramming, all the deep things) and it is one of my biggest regrets in the choice of tech. The amount of effort you’ll put into not sliding out of this crazy ride nullifies all the promises of easyness, which is limited to trivial things anyway and explodes with complexity in any non-trivial data exchange. Its only upside is low footprint, but I fail to see where it matters today (apart from nodemcu whose active users could probably fit in one closet).
https://github.com/nodemcu/nodemcu-firmware
Based on Lua 5.1.4 or Lua 5.3 but without debug, io, os and (most of the) math modules
As expected, they didn’t bother to support all versions and probably were done with it after 5.4 announcement.
I was infected by the Lua mind virus 15 years ago and I have not recovered.
I simply don't see any reason not to use it .. for everything.
I've built games with it. I've built GUI's with it. I've built scientific analysis tools with it. I've used it as a total solution for previously-impossible embedded problems. I've used it for desktop applications and mobile apps. I've automated entire production lines with it. It has huge appeal as a general purpose software development ecosystem - but those who know how to do this, tend to keep it to themselves for some reason.
It can do everything.
There's just nothing I want to do with computers that I can't, legitimately do, with Lua - or its VM. Or, LuaJIT. Or, all of the above and a bit of luarocks built in. Throw some luastatic in while we're at it, bundle it all up as a .deb, and nobody needs to know a thing.
Its just so versatile. I hope someone builds an OS around it some day, making everything and anything the user wants to do, accessible through a Lua module, or some smart libffi wrappers around a handful of .so's, somewhere ..
In my retirement, I'll take antirez' LOAD81, turn it into a proper Lua editor, add integration with luarocks and luastatic and maybe a shit-tonne of IPFS, and then there won't be any need, ever again, to deal with anything else.
It's my language of choice for letting users customize an app, but the last client wanted Python because many people are already familiar with it and 'Scriptable with Python' looks better from the marketing point of view(
[flagged]
[flagged]
nah, it's overrated ackshulaly
Meh. I don't get the love Lua gets on HN. At least version 5.1, I didn't try the others.
No first class support for OOP, you got to use tables instead.
No "continue" keyword to go to the next iteration of a loop. So you have to use some ugly elseif.
No try catch!
It's a dynamic language so everything goes. A function will return nil or a number or whatever you wish. A function can also returns any number of variables, so obviously some moron will abuse it: looking at you Blizzard intern (you must have been an intern right?) that thought returning 20 variables on the combat event log was a good idea. Ever heard of tables???
The LSP can't do miracles when there are almost no rules so auto-completion is more miss than hit, which is quite shocking in 2024. The IA is helpful sometimes but create subtle bugs some other times. A simple uncaught typo will create a hard to find bug (yesterday copilot auto-completed myObject.Id instead of myObject.id, there went 20 minutes of my life trying to find why some code that was running solidly for weeks was now failing silently).
So all in all, Lua is fine to write small imperative scripts of a few hundred loc. Anything bigger and more complex you should run away IMHO.
I never realized C# was such a well designed language until I tried Lua.
When it comes to languages, I was enlightended when I changed from {}; languages to Python. I could never go back.
Out of curiosity: does this post read like LLM (generated or assisted) to anyone else?
Lua is great to embed, but for Redis I picked it as a scripting language with many regrets because I don't like the language itself: it looks almost like designed to have some kind of friction compared to what you expect to write in a language that is at the same level of abstractions. Little design decisions here and there that cumulate into a language that is somewhat hostile (for me, at least). Yet, it is so fast, easy to integrate, small footprint and reliable, that many times it is still the way to go. Btw, the hostility is present even at C-API level, with the stack approach: it's not rocket science but more cognitive load than needed. Even if I was exposed in the past to stack languages like FORTH, I still had to do some mental gym while writing the bindings. Why?