lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sun, Sep 24, 2000 at 11:01:34PM -0000, Sebby  wrote:
> I'm a software engineer for a video game company. We currently need a 
> scripting language to control various parts of our next generation of 
> games (AI, SFX, animation, GUI, ...). Oour original plan was to write 
> our own compiler + VM (i have written some in the past so it's not an 
> unfamiliar territory for me).
> [...]
> However, now i have stumbled on Lua and wonder if it would be a 
> viable alternative. Writing our own compiler and VM would be time 
> consuming where as i am assuming i can have Lua integrated into our 
> engine in 1-2 days of coding (versus a few weeks for our other 
> alternative).

This thread is getting increasingly common as the popularity of Lua among game developers spreads.  Maybe a section in the faq is warranted regarding Lua's suitability to various situations, with game development prominently among them?  Perhaps links to the (many) relevant threads in the list archive?  

I'll throw Grim Fandango and Escape from Monkey Island onto the pile along with MDK2 and Baldur's Gate.  It might behoove us to get a more detailed list of commercial games utilizing Lua (come on, I know you're lurking out there!) simply to prove the point.

> * Lua can be extended through function calls. Unfortunateley, this 
> implies writing a stub function to grab the parameters from the Lua 
> stack and call the actual function (this is pretty much the same 
> thing i did with a VM i did, except it could also call functions in 
> objects in C++). Now, i'v heard mentioned somewhere in the mailing 
> list there was a more efficient way of extending Lua. Is that so? And 
> how?

As others have mentioned, SWIGLua and tolua are your friends.  Even if those are unsuitable, the API for grabbing arguments and returning values is very clear, and not hard to maintain.

> * Since our next generation game engine will work on a limited set of 
> platforms (PC, Playstation 2, X-Box). How hard would it be to write 
> optimized versions of the VM for such different plateforms?

I'm not sure what you mean by "optimized versions of the VM".  The VM itself is pretty tight and simple, especially with the upcoming changes in 4.0.  Do you mean optimized at the assembly level?  As others have said, your scripting code should not be the place you'll put your biggest candidates for optimization.  

I'd suggest that as you write your Lua code you make sure you can throw pieces of it that you're not using out of memory, and get them back when you need them.  We didn't do this on Grim.  As the game grew, we had ALL of our code loaded at once, even for rooms you probably hadn't played in for several hours, with about 2MB of overhead just to have it all loaded.  Our savegame dumped out the entire Lua environment; despite using zlib, our savegames were quite, uh, hefty.  =)  The first thing we did when we started Escape from Monkey Island was to modularize the code so that only what was needed for your immediate surroundings was loaded at any given time... Think of this as level-specific or region-specific code.  Any resource management you do that manages textures, geometry, sounds, etc. for a given part of your region should incorporate the availability of Lua code.

This also makes things a lot easier to debug.  =)  Of course, this was just a matter of being sloppy about coding in the first place.  Lua itself is tiny.

> Any feedback will be greatly apreciated.

Overall: Using Lua on Grim was a pleasure.  I cannot possibly recommend it highly enough without boring a lot people to tears; search the mail archive for my long summary of how we used it on Grim.  

If you have specific questions about Lua on the PlayStation2, feel free to direct them to me as it's now my job to help you.  =)


"Why, that's the second biggest monkey head I've ever seen!" --Guybrush
"LeChuck's dead. I blew him into a million gooey pieces."    --Guybrush
Bret Mogilefsky  ** **  Programmer, SCEA R&D