views:

10701

answers:

25

Why is Lua considered a game language?

I have been learning about Lua in the past month and I'm absolutely in love with the language, but all I see around that is built with Lua are games. I mean, the syntax is very simple, there is no fuss, no special meaning characters that makes code look like regular expressions, has all the good things about a script language and integrates so painlessly with other languages like C, Java, etc. The only down-side I saw so far is the prototype based object orientation that some people do not like (or lack of OO built-in).

I do not see how Ruby or Python are better, surely not in performance ( http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=lua&lang2=python ). I was planning on writting a web application using Lua with the Kepler framework and JavaScript, but the lack of other projects that use Lua as a web language makes me feel a bit uneasy since this is my first try with web development. Lua is considered a kids language, most of you on Stack Overflow probably only know the language because of the WoW addons. I can't really see why that is...

http://lua-users.org/wiki/LuaVersusPython provides some insights on Lua against Python, but this is clearly biased.

+23  A: 

Languages rarely become popular simply on the merits of their technical features. Ruby languished for a decade, more or less, before people noticed it because of Rails. Lua would be a complete unknown without WoW's programming APIs. Lua is no more a "gaming" language than Ruby is a "web" language.

Brad Wilson
except for the fact that lua is not only used in WoW, it is used in a wide variety of games for scripting ad-ons. This is not the answer you are looking for.
Brian Leahy
I know Lua mainly from its being the scripting language of the Scite editor.
Eli Bendersky
The first time I heard of lua was on Monkey Island 4 (the Lua Bar). Anyway, I think you are right, I guess this is mostly about luck (or unluck, depend on your point of view).
Hoffmann
I knew lua from the Baldur's gate lua Console... Is great to code quick script, espacially AI scripts, so it had his success in video games and the reputation had stick to it.
e-satis
-1 Wrong answer, developers use Lua for AI scripting and game play in all sorts of games. This is as a professional Game Developer myself
Robert Gould
indeed.. i've used lua as a web templating language, and it worked just fine. its low footprint and simple structure makes it a pretty good pick for web development as well. That said, Python has a whole lot more built-in.
Sciolist
Yeah, Lua was known and popular as a lightweight embedded language before WoW. And it's mostly because of the merits of its technical features.
Dan Olson
He isn't saying that Lua wasn't used before WoW any more than he's saying Ruby wasn't used before Rails. He's saying that WoW was arguably Lua's first step towards significant general awareness, just as Rails was Ruby's.
Ben Blank
Most of the commenters here completely misread my answer. I didn't say Lua was a gaming language, I said some people view it that way because its by-far biggest exposure to the world is in games like World of Warcraft.
Brad Wilson
"rarely become popular simply on merits of their technical features"? I don't think so. Lua became popular because it has an easy API, it has fast compiler and very fast VM with low memory footprint. Lots of games used it before WoW for these reasons. And you think people made this decision without regard to the technical features?
Nick
I had never heard of it before WoW, and we now use it across our whole product line of embedded devices.
Dolphin
Something similar happened with Javascript: Google mail and maps provided the first applications most people saw that did something <i>useful</i> with javascript, whereas previously its use had been limited to small gimmicks.
pjc50
LUA was used in plenty of games way before WoW, Grim Fandango being one of them and it was popular precisely because of its technical benefits (easy to embed, small footprint, ...). On top of that most other languages just aren't build as extension languages, but instead assume that they have full control over the process, making them fragile and insecure.
Grumbel
Lua's a lightweight language, without a ton of overhead, and is very easy to embed into a game without the overhead of a VM, etc. Because of this, it's widely known and used in the game industry, and has some level of network effect. It's good for games, so people used it and it got popular. It got popular in the industry, so people in the industry are more inclined to use it as knowledge of it is widely available.
kyoryu
Lua's also used in some embedded controllers now
0A0D
Sure, but the fact is that the biggest exposure most people had to Lua was WoW. My first exposure came from Angband, long before there was a WoW. My son's learning it to do things in Roblox, which is a MMORPG that uses blocks that look a lot like Legos without violating copyrights, patents, or trademarks.
David Thornley
Luke's answer is more accurate with regards to motivation, history and the implementation of Lua in game systems together with the suitability for applications other than games.
Kynth
+9  A: 

Last time I looked at Lua (just before falling in love with Python), this was version 4.0, 5.0 there too, there were a ton of Lua distributions around: Each with its own set of libraries.

What makes Lua a game language? Without a standard library that can actually do stuff I would want to do, it is limited to areas where this isn't much of a problem: Embedded scripting languages. You're not supposed to be able to do stuff to anything but your embedding application (game, editor/IDE, etc.), and a lack of standard library is a plus here!

Daren Thomas
Lua is supplied as source code and was designed to be an embedded language. A small set of standard libraries is supplied, but the idea is that you expose your application to Lua so that you can script things. These is no sense in having a standard "game library" as all games are different. Python is more of a standalone language and has more general purpose libraries. I use both for different purposes.
Nick
Lua is a natural fit where a plugin language is needed. Games need plugins. Lua == game language: Missing a logical step here. Once you see the "I need small, embedded language" is a common requirement for game development, you see why Lua is so often embedded into a game. Ironic then, that the OP is "worried" about using something that "is only for games", when in fact, game developers tend to not use anything that isn't super reliable. So, if it's good enough for WoW, it's NOT good enough for your lil' website? :-)W
Warren P
+1  A: 

Lua is a scripting language, I've actually only seen/used it in the lighttpd and MySQL (MySQL Proxy) areas. I've personally played with it when experimenting with the MySQL proxy.

I never heard of it as a game language. I think Lua was primarily written to be embedded in other languages and to still offer great performance. Due to its nature (compiled bytecode), it's also platform independent which is sometimes a huge advantage.

Some people also think of Lua as a configuration language since its syntax is pretty elegant and simple and suitable for configuration files.

As for stand-alone, I wouldn't know how to get started. I'd have to research this as well. If you are just doing it for the sake of research and learning, then it's great - but I wouldn't do it just because it's possible.

Till
+4  A: 

From your link:

Python has a nice simple syntax and behaves "as you would expect". ie. no gotchas for scripters like undeclared local variables default to global.

[...]

Lua programs are much more error prone, due to automatic coercion, accessing of unset variables without an exception, and having to check most functions for nil values, rather than just catching the exceptions.

[...]

Lua handles only one type of numbers, usually C doubles or floats, which can lead to overwhelming processing.

In short, Lua is designed to be a small simple language for the scripting of applications. There's nothing wrong with this, and it's an excellent language for its intended purpose. But for writing applications entirely in Lua, it's a nightmare.

John Millikin
"But for writing applications entirely in Lua, it's a nightmare." I this from personal experience? What were some of the problems you faced? Did you write the original code or were you a maintainer?
Jon Ericson
Some experience with Lua, and much experience with similar "loose" languages. The "all numbers are floating-point" means slow and inaccurate math. Type coercion, automatic globals, and no error on failed attribute are also features of Javascript -- ones I could live without.
John Millikin
+14  A: 

Lua is a great scripting language: it is extensible, it is simple to learn, and provides the basic primitives such that programmers can use OOP or functional programming (in the same league as Scheme and Javascript). It is one of the few scripting languages with support for coroutines, which help a lot when doing multi-threading programming.

In my tests (and I am an addict when it comes to programming languages) ... Lua is the fastest dynamic language I ever worked with. It is also very small, and can be embedded easily in a C/C++ application.

I think that Lua has all the qualities of a scripting language used for coding game logic. And game shops experiment with all kinds of technologies, from Lisp to Haskel, and Lua just happens to be a good compromise between flexibility and speed.

Lua is also not appropriate for web applications for a number of reasons ... lack of libraries, and (most annoying for me) a total lack of unicode support (although Ruby has this same flaw, and few people are complaining ... but still, it matters).

Alexandru Nedelcu
+1 for It is one of the few scripting languages with support for coroutines
Ian Ringrose
+115  A: 

Speaking as a game developer, the games industry loves Lua because it's so lightweight. The size of Lua's runtime, its performance and memory usage, are an incredible combination compared to other languages. Game developers are highly paranoid (whether or not justifiably) about these things, which partly explains why Python, Ruby etc haven't been used much as game scripting languages.

It's also trivial to embed, and highly portable (with all the different console platforms around, this is extremely important).

As a result, Lua is the choice of the games industry, but that doesn't necessarily mean that's all it's good for.

I would also say WoW used it because it was already popular among game developers, not the other way around. However, because WoW uses Lua to allow extensibility or customisation, rather than just as an internal technology, it certainly raised Lua's profile outside the game development community.

Luke Halliwell
The lightweight runtime is especially attractive for console developers, who must be much more careful about memory usage. On the PC side you see more developers willing to experiment with "larger" scripting languages like Python. Firaxis (Civilization IV) would be a good example of that.
Nathan
Doesn't this answer only address the "why lua is a game engine" side and not the "should I be afeared to use lua for web development" ?
Ziggy
It's Lua, not LUA. It's not an acronym. It means moon in Portuguese.
Nick
+5  A: 

Lua was used in games LONG before WoW, and had a good reputation in the industry in those times as well. The reason why Lua is picked for games is because it's very lightweight, and simple to learn. Ruby and Python are more powerful languages, but to achieve that they lost speed and a bit of simplicity.

It's not a question of which language is "better". It's a question of which language best suits you needs. Ruby became a web language because of Rails, but it's a more than decent general purpose language as well. It would just never be useful in games because it's dog slow.

Python is used in some big games, but not as often as Lua.

It's just a matter of asking yourself which language you would like to use most, although I think that Lua will require a lot of scaffolding code to get a web application properly working.

wvdschel
+2  A: 

Although a little off-topic, it's interesting to make the comparison with the (lastest) upcoming replacement to TeX called "LuaTeX", which will have a Lua interpreter built-in. It was chosen for all the same reasons quoted above that the game industry (apparently) like it for: lightweight and flexible, so it's not dragging a huge swathe of code into a program that is mainly looking for "just a scripting language" in which to implement algorithms and perform calculations.

Will Robertson
A: 

As the others had said, Lua is chosen primarily because of how lightweight it is. The popularity of World of Warcraft has certainly helped Lua become more known to the general public, but it has been in use for a long time. Other prominent games that uses Lua are Neverwinter Nights, Everquest 2, and most recently, Crysis.

Mythokia
Actually, Neverwinter Nights does not use Lua. NWN has its own special scripting language. However, the Baldur's Gate family of games -- also from Bioware -- do use Lua.
Adam Crossland
+1  A: 

Lua works great as an embedded language in a larger project and it's a lot easier to teach to non-programmers. This makes it a good tool in game development, as you can have game designers with close to no knowledge of general programming techniques testing and modifying AI and quest scripts and the like.

Add to this its performance profile (both memory and speed-wise) and its permissive license (you can basically do whatever you want with the interpreter) and you'll see why it's such a hit.

Pedro
+3  A: 

Adobe also chose Lua for writing Lightroom plug-ins.

I haven't done anything complicated with it yet, but so far, so good...

and as I have since been told/discovered, most of Lightroom is written in Lua.

Mikezx6r
IIRC, most of Lightroom is in fact written in Lua, not just plugins.
Matthew Schinckel
+6  A: 

Just to correct David Locke's post, in which he wrote:

Python is distributed under the GPL. This means that embedding the Lua interpreter in you game won't require you to distribute the source code to the game.

Python is distributed under it's own license and even clarifies:

There is no GPL-like "copyleft" restriction. Distributing binary-only versions of Python, modified or not, is allowed. There is no requirement to release any of your source code.

Matthew Trevor
This does not answer the question.(You should downvote the respective answer, and supply a comment, instead.)
Arafangion
@Arafangion, it answers the question indirectly as the author is comparing Lua with Python. I'm voting +1 because people thinking Python = GPL is a common misconception.
Unknown
+3  A: 

I've been fond of Lua since 2002 - 6 years now. It's foremost publicity comes via games, but they are in no way the "the" thing of the language. Lua wasn't even created with games in mind.

However, games do benefit from all the goodies of Lua; high performance, good productivity, small footprint, very high portability. One reason why Lua's been big there is that unlike desktop world, game scripts don't traditionally need to be backwards compatible.

To me personally, Lua is about the merger of Lua and C(++). It's about two languages working together, and bringing more onto the table than any single language does. Objective-C is like two languages baked in one (bad, because brain needs to jump line-by-line instead of by source file). C++ and C# will by definition not gain the dynamicity benefits of dynamic languages.

I know some people behind the Kepler effort; they sure are using it and there's support. You won't be alone. :) Welcome.

akauppi
+5  A: 

I'm surprised that no one has mentioned the Big Three of network security yet. Lua is used as an embedded language in nmap, snort, and wireshark. Writing a Wireshark packet dissector is an exercise in concision. A carelessly written dissector will really slow you down when you have a few hundred thousand packets to load. Lua is fast, as many have said already.

Excellent observation. Seems a natural choice for product extension.
unhillbilly
+2  A: 

Actually, LUA was widely used for game scripting way before Blizzard used it for World of Warcraft GUI modding.

One of the best graphical adventures of all times, Grim Fandango, was fully scripted in LUA.

On a related note, the newly released MMORPG Warhammer Online also uses a mixture of XML and LUA for it's graphical user interface.

Vicent Marti
love that game :D
George
+3  A: 

Think about what is required to actually make a game; I think it's actually a compliment to the language. Graphics programming (lots of heavy 3D math), interface programming, physics simulation (again, hardcore math), AI, and all running at 60 Hz. And on a console, you pretty much have to pack your own OS; there's no 'malloc' or 'fopen', you need to provide memory allocation, IPC, sometimes even a scheduler. And your own scripting environment, including all the interface between the core and the VM (you're not just running scripts on top of a framework that somebody else ships, you have to build your own). And Lua is perfect for this, because of the reasons mentioned before.

So unless you're some kind of badass kernel hacker, you don't get to call game development a task for "kids" :)

Hello, 1990. Modern consoles provide all sorts of OS support.
Robert Fraser
What? Every console I know runs an operating system. Heck, Xbox 360 provides a full-featured framework and lots of tools (and the other bigs ones probably do as well).
iconiK
+1  A: 

To Till and Tanoku: Lua is not an acronym, it just means moon in Portuguese (coming from Brasil).

Lua is used in many applications beside games. For example in SciTE, a lightweight text editor. It is also used a lot in embedded platforms. A number of applications using Lua are listed in the Lua wiki and Wikipedia. Indeed, the fact it is very portable (runs on nearly all platforms, including game consoles from Xbox to NDS), lightweight yet powerful, fast and easy to integrate to C or C++ code (and other languages as well), and with a user-friendly syntax (important to be used by game designers or other non IT professionals) makes it a first choice as scripting language.

PhiLho
+1 It's Lua, not LUA
adam_0
A: 

A non-game example of the use of Lua : rewriting DNS answers with the PowerDNS name server.

bortzmeyer
A: 

Check out the Squeezebox Duet and Harmony 1100 from Logitech. Both use Lua, and with the Duet you can even write your own plugins in Lua.

patros
+1  A: 

The Python Software Foundation License (PSFL) is a BSD-style, permissive free software license which is compatible with the GNU General Public License (GPL). Its primary use is for distribution of the Python project software. Unlike the GPL the Python license is not a copyleft license, and allows modifications to the source code, as well as the construction of derivative works, without making the code open-source. The PSFL is listed as approved on both FSF's approved licenses list, and OSI's approved licenses list.

tl;dr PSFL != GPL

A: 

Having used Lua extensively, I see why it's not used more often in non-game projects. Its dynamic nature and default global scoping doesn't play well for writing large applications. It can be done, but you'll have to be aware of those 2 issues and program around them (your own typing scheme and global guards).

A: 

To add to the amount of applications embedding Lua you can now add VLC.

Roman A. Taycher
A: 

For some background on the history of Lua in game development check out the slides from the GDC 2010 tutorial "Lua in Game Dev": http://kore.net/company/luagamedev.html.

+1  A: 

I just want to underscore a point that's been made here already. The three things that make Lua more attractive to a game developer than other interpreted languages are:

  1. Memory
  2. Memory
  3. Memory
Crashworks
+1  A: 

Lua is popular because is it very quick to achieve simple tasks. I've been looking at LOVE, which is game framework built using Lua, and you really can get up and running with just a few lines of code. You don't need any special IDE (any text editor will do), and your code is not bogged down with a whole bunch of package, class and import declarations. Best of all your game will run on Windows, MacOS and Linux without any changes.

LOVE Game Screenshot

Phyxx