

Ask HN: Why Lua? - gmaster1440

Why would anyone use Lua? What advantages does it offer that languages like js and ruby don't? I'd really like to know because it seems as if there are a decent amount of developers writing in Lua, but I can't seem to understand why?
======
MattJ100
I first got into Lua when a number of years ago someone (thankfully) pointed
me to it to save me writing my own scripting engine for an application.

As one of those people crazily obsessed with pursuing simplicity, I really
grew to appreciate Lua's design[1]. I started embedding it into any place I
wanted simple extensibility in applications. Gradually I found myself writing
more and more and more application code in Lua.

This didn't turn out badly at all - Lua's performance is really very good
compared to any alternatives, and development was also much faster. With its
easy interfacing with C there wasn't really anywhere I couldn't fit it. Lua
being so flexible is probably one reason I really can't put it down now.

A couple of years ago I decided to develop an XMPP server (that's another
story...). The choice was essentially between C and Lua, myself not liking
Java and things like Python/Ruby being too heavy. In order to get off the
ground I decided to write entirely it in Lua, and then port each component to
C later. I'm happy to say I've continued to be impressed by Lua, both in its
runtime performance and the speed and ease at which we can develop code. I
have no plans for the C rewriting anymore - we already compare quite
favourably with an equivalent erlang server in benchmarks.

Interestingly the "Why on earth did you choose Lua?" comments I received at
the start have significantly died off over time. I'd like to think that people
really are dropping the "Lua is only for games." stance - in my opinion this
language is drastically under-used.

Also (despite a few inaccuracies) there was a good short talk posted recently
about Lua[2]. My main quibbles are for example that Kyle repeats that Lua
doesn't have print() built-in. His talk is primarily from the embedding
perspective, and when embedding, yes, you have to explicitly pull in the
standard libaries - but print() is certainly there, along with various other
things. Secondly he claims that Lua does not interface well with Java, yet
there are several projects allowing exactly that[3]. There are even a few Lua
implementations /in/ Java[4].

[1]: Slides from a talk at Stanford by one of the Lua author's on design
decisions made in Lua:
[http://www.stanford.edu/class/ee380/Abstracts/100310-slides....](http://www.stanford.edu/class/ee380/Abstracts/100310-slides.pdf)
[2]: <http://kylecordes.com/2010/lua-strange-loop> [3]:
<http://www.keplerproject.org/luajava/> [4]: <http://lua-
users.org/wiki/LuaImplementations>

~~~
deathflute
Do you have any references comparing the performance of lua with other
scripting languages? Thanks

------
mhd
It's easy to embed and has a very low footprint, plus it's quite fast. Those
are all important for game developers, where usually awful C-like NIH
languages abound. You can't carry a lot of standard library baggage with you,
which is very hard on languages like Python or Ruby (Tcl fares a bit better,
for historic reasons).

And – speaking of historic reasons – correct me if I'm wrong, what good
embeddable JavaScript interpreter would you have used five years ago?

Also, compared to Ruby and JavaScript, it's a much simpler language. You have
to learn a lot less and deal with fewer idiosyncrasies, which often hurts
people who "just" write scripts for big systems.

------
beagle3
\- embeddable inside your application

\- modest resource requirements

\- runs on everything (embedded, game consoles, etc.)

\- has a JIT compiler that is way better than any Ruby/JS/Python JIT (and in
fact in many cases better than a good Java compiler).

\- Simple and regular syntax

\- Vibrant and helpful community.

It's not the right choice for web development, because that's not where its
echosystem is (although you can do that if you want). Other than that, the
only drawback I can think of is that arrays start at 1 rather than 0.

~~~
squidbot
I agree with all of the above and will ad a few things that attracted me to
use Lua as the scripting language for our game engine:

\- Data can be easily constructed inline without a lot of extra syntax

\- The interpreter is very fast

\- Functions as first class objects

\- Closures

\- Meta-tables

All of these things make Lua very expressive and concise for designers, while
giving a lot of control to make things work correctly to the programmers.

A few cons: \- the built in error handling is not great, we corrected it.

\- variables are global by default, which can make typos become runtime
errors, we corrected this as well

------
pietrofmaggi
From my point of view, Lua is very light and easily embeddable inside an
application.

It has a nice, clean C implementation and can be easily cross-compiled.

I normally use ruby for a complete different set of problem (scripting on
OSX).

