
Ask HN: What is so special about Lua? - dorfuss
I&#x27;ve heard about Lua in a couple of places but I&#x27;d like to hear from people who actually do real stuff in the language. What is is better in than other languages? For what purposes?
======
enkiv2
Lua makes for an ideal language to embed in a larger project. Structurally,
it's like python, but it's smaller and more internally consistent (without the
large standard library), faster, and has a nicer C API.

Because Lua is an academic project, it has different pressures than a
primarily practical project like python or perl. The Lua source code fits on a
floppy disk, is pure C, and is clear and well-written.

As for what's (arguably) bad about Lua:

1) it doesn't have nearly as large a community as other similar languages, and
what community it does have is in many cases split up between software
packages that use it as an extension language or a configuration language. The
config files for awesome and for ion are written in Lua, but that doesn't mean
you can take the configuration for one and port it to the other. Likewise, WoW
and photoshop both make use of Lua for scripting. I get the impression that a
lot of people who use Lua don't realize that it's a general purpose language
and an independent project.

2) It lacks a strong standard library, and many really common things (like
sockets) aren't built in. Until version 5.1, importing installed packages
wasn't even a completely standard part of the language. More complicated
packages often exist but are fairly obscure, and there's no gem/npm/pip style
system for pulling packages down automatically or managing their dependencies.

3) There are some odd limitations here and there. In 2007 I was working on a
project in Lua that took advantage of a single very large table -- and learned
that there was at that time a limit of 2^13 string keys. I think that limit
has since grown, but it's unusual for a scripting language to have such a low
limit for anything (aside from recursion depth).

~~~
stevekemp
The fourth complaint is that it is developed largely without any public
discussion - new releases land, and suddenly there are API changes you must
include.

I've written a mail-client which is both configured and scripted with Lua. For
ease of embedding it works really really well, and coding it was a pleasure.
But I'm still disappointed when I have to update for new Lua releases (e.g.
5.1 -> 5.2 required some changes I wasn't expecting.)

------
sebcat
LuaJIT makes Lua stand out from Tcl, Python and others. But you really need to
ask yourself if you need that performance. If you just need something to glue
various components together I would suggest Tcl. Tcl's syntax makes it really
easy to use for simple things, and the C API is really nice to work with.
Though Tcl is not a good idea for larger code bases IMHO, or code that needs
to run fast.

------
fit2rule
Off the top of my head what makes Lua an excellent tool for the modern
developer:

1\. You can put it anywhere you've got a C compiler. Any collection of C
libraries can be glommed into the Lua VM and made into a framework - with a
modern scripting environment - with relative ease.

2\. The language is very easy to learn, and easy to teach. Its simplicity
yields a lot of power, too.

3\. App logic in Lua, App engine in C. Enough said. ;)

------
asow92
Lua is a fun language with okay performance. My understanding is it's a lot
like scripting C, as it's implemented directly atop C.

Data structures in Lua are based off hash tables, basically everything is a
hash table.

Lua has first class functions, garbage collection, closures, and a bunch of
other neat stuff.

It's certainly worth looking at if you've got spare time.

------
dottrap
Lua is a language that is designed to be embedded, which is rare in this
world, thus it lacks the arrogance that it has to do everything. This allows
Lua to focus on specific things so it can excel in those areas like the
scripting domain, and knows you can and should do the low level things in the
host language (e.g. C).

Lua is small, lightweight, fast, and elegant. It is one of the few languages
that tries to remove features instead of add them. It likes to give you
mechanisms to build more powerful features (like metamethods), instead of
making the language bigger and more complicated and redundant. These
mechanisms feed back into the notion that it is a terrific language for
embedding, to allow you to make a Domain Specific Language for your specific
needs.

Because the language is so small and clean, it is also the reason it is fast.
Then something brilliant like LuaJIT gets created, and can realize the dream
of outperforming optimized C code.

Also because the language is small and clean, it is a much easier language to
secure and use in secure environments. Wikipedia uses it now for their
multimedia scripting engine because it was small, fast, and easy to audit for
security. Lua is also sandboxed/secure by default. It was also easy to modify
for their specific needs (like embedding in PHP). And Verisign uses it for
their high reliability transaction servers because they had the bold idea of
using a foundation that was auditable for reliability instead of spending lots
of money to build redundancy expecting the platform to constantly crash.

Lua's original popularity was in embedded devices because it is so small, it
is one of the few languages you can get on a embedded device. It is also
written in 100% clean/ANSI C (no platform #ifdefs needed) so it ports
everywhere there is a C compiler (which is everywhere).

Lua caught on in video game development in the late 90s and became the
dominant game scripting language in the industry. It is a great language to
embed and interoperate with the C/C++ engines. The high performance stuff
would still be done in C/C++, but the higher level content could now be done
by artists as Lua is one of the cleanest and simplest languages to learn. And
on the performance front, another thought exercise told to me recently was
that Lua is about 100KB; that means it can now fit entirely within a modern
desktop CPU's L2 cache which is a huge performance advantage.

If you want a kitchen sink language that has every library included from the
start, there are languages better suited for that than Lua. But if you have
specific needs like being embedded in a native app, or small footprints
(memory constrained, CPU limited), and specific libraries you want to bind, or
want security and sandboxing, Lua shines above all in this domain.

------
blazing_grey
See also time & space - a Lua interpreter starts about 3-10x as fast as
Python, and takes 1100k of RAM to Python's 4M. This matters on a small machine
like a Raspberry Pi.

------
taf2
embedded in nginx it adds an extra layer of customization for say doing server
side includes or security checking sessions. You can even use it in nginx to
assist in caching around your application. Embedded in redis you can do
transactional things over multiple data structures, making redis even more
powerful/flexible... the language itself is super simple so it doesn't take
long to get familiar with it..

