Why is Lua such popular?

September 16th, 2007 by Ralf S. Engelschall


A steadily increasing community exists around the programming language Lua, especially in the games related industry. In case you don’t know it: for instance, games like Far Cry or S.T.A.L.K.E.R. use Lua as an embedded scripting language.

academic thesis

And there are Unix applications like RPM 5 and Monotone which also embed Lua as their programming language for scripting extensions. In RPM 5 one can code .spec macros in Lua via %{lua:...} and in Monotone one can hook into the run-time processing of the application by declaring Lua callback functions in ~/.monotone/monotonerc. Having such an embedded scripting language in an application is great for hackers like me as it allows to adjust and extend applications easily and flexibly.

writing college essays


But, why is the IMHO still somewhat “esoteric” and syntactically even partly strange language Lua used, and not for instance the more popular and both syntactically more appealing and semantically more powerful language JavaScript? What I’m talking about? Well, for instance: have you ever tried to find an employee who is able to code in Lua — versus someone for JavaScript?

Additionally, AFAIK Lua doesn’t even provide any really new language concepts others like Perl and JavaScript do not have. Sure, Lua is meant to be simple, but sometimes its simplicity becomes nasty. A little bit more functionality sometimes would be not too bad.

Common Idioms

And finally, C, C++, Perl, Java, and JavaScript at least syntactically share two common idioms: the braces for blocks and the semicolon as statement terminators — something we all got used to since decades! Lua OTOH uses then, do and end for blocks and the semicolon is just a statement separator in case one wants to put multiple statements onto the same source line.

Sorry, perhaps its just me, but when I have to code in Lua I constantly feel like I’m still 15 and sitting in front of my C64 and its BASIC interpreter. Sure, as a computer scientist with a strong focus on formal language parsing I know best that this issue is just about harmless “syntactic sugar”. But, sorry, IMHO it nevertheless hurts in 2007 when the whole world (just let us ignore the Python guys here ;-) already got strongly used to the block braces and statement termination rule.

“Simple API” for JavaScript to the rescue?

But, what I find most strange about Lua is the fact that IMHO its popularity doesn’t come from the fact that it is the greatest language since sliced bread, but because it has a small code footprint and (at least it seems at the first spot) to be easier embeddable into a C or C++ application. It is correct that here Lua has some advantages over complex APIs like Perl/XS, JNI, etc. But if THIS is the whole problem, why is nobody just coding a “simplification wrapper” for SpiderMonkey’s API (and bundle it as a out-of-the-box part of OSSP js ;-) and this way allow one to embed JavaScript into an application as easily as Lua.

If low footprint, then really low footprint, please…

Or to stretch the point even further: if low footprint is really the ultimate reason for Lua (which is 13K LoC) and a reason against JavaScript (80K LoC) or even Perl (105K LoC), then I still do not understand why people not even use for instance Arena (14K LoC) or even NASAL (5K LoC). Arena and NASAL both at least are a lot more C/ C++ /Perl/ Java/ JavaScript style in their look and feel and so at least attract the “old-style” coders a lot more.

Lua: the MySQL of scripting?

I really don’t want to be unfair, as Lua definetely is a rather well engineered solution. But I cannot resist associating Lua to MySQL all the time: a solution I personally always resist to choose because if I want really small footprint then I use SQLite (or Arena/NASAL in the Lua case) and if I really need sophistication and power I use PostgreSQL (or Perl/JavaScript in the Lua case). So, Lua certainly has its good place in the world, I just still do not understand this place well enough. And especially I do not understand why more and more projects intentionally use the “esoteric” Lua instead of the obvious “mainstream” alternatives.

Well, I’m still hoping I totally overlooked the absolute killer feature of Lua and that someone then will tell me that I’ve no clue and better should shut up. But even after coding a larger bunch of LoC in Lua I’m still not feeling “smart”. At least in all of the other mentioned languages I had this feeling rather quickly (after about a few thousand LoC). I think I will never really understand the attraction of Lua…

Leave a Reply