Extending Games With Lua 55
RealDSmooth writes "2old2play.com has a nice article up about extending World of Warcraft, Neverwinter Nights, and other games using Lua, a light-weight programming language made specifically for enhancing and extending games. It goes into some great details about what's available today, and where Lua is heading in the future."
Umm, no, not specifically for extending games (Score:5, Informative)
I've been working with Lua off and on for a while. I have to say that it is pretty darn cool. It is really easy to embed, really easy to extend, and really lightweight (about 90k or so). The language is very simple, but still supports a lot of advanced programming concepts like closures.
Not really well researched article (Score:4, Informative)
LUA was used for scripting in Baldur's Gate series however.
BioGeorg
Pretty lousy article... (Score:4, Informative)
Aside from the fact that it appears to have been written by somebody whose teachers apparently overlooked the usage of the apostrophe when teaching him English, the article didn't really say all that much. Reading the summary, I was expecting some details about Lua itself, or maybe even some information about where it is headed in the future. All the article pointed out was that Lua was being used in some games. ...... Real informative.
But seriously, Lua's a great language. Full lexical scoping and first-class functions alone give it insane flexibility and power, and its table data structure is implemented very well. In general, Lua is one of the most well-thought-out languages I've ever seen; its creators have taken great pains to get all of its functionality into it while still maintaining a low profile (the stand-alone interpreter takes ~150KB of space) without resorting to kludges or hacks, and these efforts have paid off. I wouldn't think of using anything else to extend a program.
Game Development with Lua, other projects (Score:4, Informative)
However, Lua is used for other things [lua.org], includinge the ion [cs.tut.fi] window manager, the SciTE [scintilla.org] editor, the Elinks [elinks.or.cz] text webbrowser and more.
Lua is simple, functional, and ideal for games (Score:4, Informative)
The entire manual that explain the whole language as well as the C embedding interface and the optional standard libraries is probably less than 100 pages printed. The source code is around 10,000 lines of C code, I believe.
Performance was also particularly impressive provided you know what you're doing. If you're new to functional programming, you might want to read up a bit. Also, it is a good idea to have experience with recursion and other such elementary topics.
Overall, I couldn't believe how easy it was to build Lua into my little project and I doubt I'll ever take a look at another scripting language because Lua is just that good.
The scheme I chose to use for my project is that it reads in all the Lua files in a directory and using the game engine's simple API (in Lua), different scripts add things like ships or new weapons. This allows the player to write a quick script for a new weapon (e.g. a rail gun), drop the script in a directory, start the game, and then use that weapon. There's basically no overhead. I think that's pretty cool and encourages people who don't know how to make an entire game to still have a fun time extending the game by themselves.
Ooops..Linky (Score:3, Informative)
mangband/tomenet (Score:3, Informative)
Re:Python? (Score:3, Informative)
Could make for some neat mods. I'm hoping we'll see some kind of Master of Magic game come out of it.
Re:Python? (Score:4, Informative)
It takes a lot of work to rip out all that dangerous stuff and convert Python into a vessel appropriate for running untrusted code. Because any game with a scripting engine will be modded, untrusted code is a given.
I Love Lua (Score:4, Informative)
I've embedded Lua into all sorts of things. Never really finished any of it, but I did embed Lua into the BUILD engine to replace the game code written in C. I've also been working on embedding it into Quake 3 Arena to do similarly, though unfortunately real life is getting in the way of doing much there. Lua is great because you can make what you want with it. It has no builtin functions, so it's completely up to the embedder what gets included. The bundled coroutine library is very useful in games, too. It doesn't even have an object model of its own, meaning that you are free to invent one based on the simple structures it provides.
The adventure game Grim Fandango was based on Lua, as was the latest Monkey Island game. Lua gets everywhere. It's in text editors, web servers, games, your shell... you name it. It's probably somewhere on your computer right now, hidden inside some application.
lua operators or, and are cool (Score:1, Informative)
so instead of
PHP: doSomething(isset($a)?$a:-1);
you can do:
Lua-like: doSomething(a or -1)
This removes the redundancy in the php statement.
I felt the embedding of lua might be kind of hard, it looked like programming postscript to me
Lua's sandboxing (Score:3, Informative)
Both of those apply. As Lua is fully reentrant and tiny, you can have any number of Lua VMs active concurrently in a program, and they're all naturally disjoint from each other.
In addition, Lua execution is inherently sandboxed with respect to the operating system because the base interpreter provides no system functions at all, and so it can affect only its own internal state. You need Lua's standard libraries before you can do file operations etc with it, but those libraries are available only if the designer chose to link them in to your executable, so the sandboxing is unbreakable "by default", bugs excepted.
Diametrically opposed to the above, many other Lua executables exist which contain dynamic loaders to allow the interpreter to be extended on the fly with arbitrary code, ie. to provide high functionality rather than sandboxing.
Lua can be pretty much anything you want it to be. The base VM just gives you efficient and flexible scripting, and imposes no usage policy at all.
Re your point about Tcl, that language suffers from its string orientation when applied to gaming, although it's fine for embedding as a simple configuration language. Lua is stunningly fast, so its use in games goes far beyond mere configuration and UI scripting, right into the hearts of engines.