tags:

views:

1211

answers:

6
+13  Q: 

Advantages of Lua

The only thing I know about Lua is that it is used to develop Ion (which is a tiling tabbed window manager designed with keyboard users in mind.)

Since I'm on SO, I can see some question about Lua, about 80 question with this tag, so I was wondering if someone could tell me briefly what this language is about and what are the advantages and drawback of it.

+2  A: 

I personally think the main advantage is that it's easy to embed in other applications.

It's also a very nice language, but most other nice languages are more painful to embed.

It compiles on almost every platform, it is small and unintrusive and has a great C api making data passing and native function implementations easy.

Laserallan
+4  A: 

One field where Lua is often used is game scripting. I can think of the following advantages:

  • It's easier and faster to express behaviour of game characters and environment in Lua than in C++.
  • Lua is interpreted, so you can simply change the script while the game is running and see if the new changes work.
  • Lua allows level designers (usually of lower technical grade) to work on creating new levels / missions etc without being able to wreak havok to the with the core game engine.
Adrian Grigore
+2  A: 

I'm sure there are many technical advantages, but for me it's just fun. It reminds me a bit of my early experiences with Perl.

I like the way tables work and that functions are first-class values. I like how clean and compact working code can be. I like metatables and metamethods.

I don't like that variables are global by default.

Jon Ericson
Can you develop a bit more how things you like works as I don't know how Lua code looks like.
claferri
+1  A: 

Lua is small, clean, and relatively friendly to non-programmers. It's designed to be embedded, with a more "native" language such as C or C++ making up the majority of the functionality. The marquee data type in Lua is a dictionary, much like other high-level interpreted languages.

Lua has gained a significant following in games, where it's often used to implement high level gameplay behaviors while calling into native code for performance-intensive tasks. Anecdotally, I've heard of Lua being used in this capacity on all current generation console platforms, including the Nintendo DS (if I recall correctly).

Dan Olson
+17  A: 

Everyone is pointing out that Lua is good in the gaming space. It is. However I personally don't place its limits there.

As others have said, Lua is small, fast, and completely cross-platform (wherever there is an ANSI C compiler, anyway [they're everywhere]).

It also benefits from several clever enhancements which affect performance. Its "table" type mechanism automatically detects whether to handle a particular table as an array, a hash table, or both.

Lua has incremental garbage collection, which means that pauses to find and collect now unused data are kept to a minimum. This is completely configurable at runtime too (eg. you can pause the garbage collector during time-critical code sections).

When efficiency or system-interfacing tasks are required, Lua has a clean stack-based C API, which allows you to both embed it inside larger applications, or to extend it, through writing modules.

The fact that Lua manages at once to be so advanced, and small, and appear so simple to the user really is what I admire about it. Most people can pick it up in less than a day, the reference manual is short, the online guide and book simple to follow, and the community is wide and is experienced in a range of fields (not just games, thankfully).

Lua is therefore my choice of language for nearly all projects (mixing with C when necessary). I use it daily for this reason :)

MattJ
+5  A: 
Nick