views:

932

answers:

10

I'm a game's developer and am currently in the processing of writing a cross-platform, multi-threaded engine for our company. Arguably, one of the most powerful tools in a game engine is its scripting system, hence I'm on the hunt for a new scripting language to integrate into our engine (currently using a relatively basic in-house engine).

Key features for the desired scripting system (in order of importance) are:

  • Performance - MUST be fast to call & update scripts
  • Cross platform - Needs to be relatively easy to port to multiple platforms (don't mind a bit of work, but should only take a few days to port to each platform)
  • Offline compilation - Being able to pre-parse the script code offline is almost essential (helps with file sizes and load times)
  • Ability to integrate well with c++ - Should be able to support OO code within the language, and integrate this functionality with c++
  • Multi-threaded - not required, but desired. Would be best to be able to run separate instances of it on multiple threads that don't interfere with each other (i.e. no globals within the underlying code that need to be altered while running). Critical Section and Mutex based solutions need not apply.

I've so far had experience integrating/using Lua, Squirrel (OO language, based on Lua) and have written an ActionScript 2 virtual machine.

So, what scripting system do you recommend that fits the above criteria? (And if possible, could you also post or link to any comparisons to other scripting languages that you may have)

Thanks, Grant

+5  A: 

Lua have been used in video-game industry for years. Lightweight and efficient.

Klaim
+8  A: 

Lua has the advantage of being time-tested by a number of big-name video game developers and a good base of knowledgeable developers thanks to Blizzard-Activision's adoption of it as the primary platform for developing World of Warcraft add-ins.

Jekke
+6  A: 

Lua is a very good match for your needs. I'll take them in the same order.

Lua is one of the fastest scripting languages. It's fast to compile and fast to run.

Lua compiles on any platform with an ANSI C compiler, which afaik includes all gaming platforms.

Lua can be pre-compiled, but as a very dynamic languages most errors are only detectable at runtime. Also precompiled code (as bytecode) is often larger in terms of size than source code.

There are many Lua/C++ binding tools.

It doesn't support multi-threading (you cannot access a single instance of the interpreter from multiple threads), but you can have several instances of the interpreter, one per thread, or even one per game object.

Doub
+4  A: 
Daniel
+1  A: 

Start with Python.

If you can prove that you need more speed, then look at Stackless Python. That's what EVE Online uses for their game.

S.Lott
In my experience the downside to Python in a game environment isn't speed but how much memory it eats -- the interpreter itself is bulky and it eats unbounded heap on top of that, while a GC run can burn a whole frame and still not free everything.
Crashworks
@Crashworks: I'm sure the developers at EVE online would find that insight helpful. Perhaps you should contact them.
S.Lott
I'll make a note to ask Mr. Fannar about it in March. For an MMO it's a little different because you've so much resources on the server end and the client device is a PC, which has huge memory resources. On a console, if you run low on memory you don't start paging and get slow; you simply crash.
Crashworks
+1  A: 

Lua, and then LuaJIT for extra blaziness!

just don't expect too much from automatic C++ binding libraries, most are slow and restrictive. better do your own binding for your own objects.

as for concurrency, either LuaLanes, or roll your own. if your C++ program is already multithreaded, just call separate LuaStates from each thread, and use your own C++ shared structures as communications channels if needed.

as you might already know, the most often repeated answer in Lua is 'roll your own', and it's often the best advice! except when it's about bindings to common C/C++ libraries, in that case it's quite probable there's already one.

Javier
A: 

JavaScript may be a reasonable option, because of the mountains of effort that have gone into optimizing the various implementations for use in web-browsers.

TokenMacGuy
A: 

These come to mind:

  • Lua
  • Python with boost::python
  • MzScheme or Guile
  • Ruby with SWIG
greyfade
+1  A: 

If you haven't looked at it yet I would suggest you check out Angelscript.

I have successfully used it in a cross platform environment (Windows and Linux with only a recompile) and it is designed to integrate well with C++ (both objects and code).

It is lightweight and supports multi-threading (in the sense that the question was asked), performs well and compiles to byte code which could be done in advance.

Subtwo
+1  A: 

We've had good luck with Squirrel so far. Lua is so popular it's on its way to becoming a standard.

I recommend you worry more about memory than speed. Most scripting languages are "fast enough" and if they get slow you can always push some of that functionality back down into C++. Many of them burn through lots of memory, though, and on a console memory is an even more scarce resource than CPU time. Unbounded memory consumption will crash you eventually, and if you have to allocate 4MB just for the interpreter, that's like having to throw 30 textures out the window to make room.

Crashworks
Good point about the memory, one of our platforms is the Nintendo DS (might just end up sticking with our in-house engine for that platform though)
Grant Peters
Just so. I think Amaze managed to cram Lua onto their DS engine, but I wouldn't swear to it.
Crashworks
At my dayjob we have two almost finished NDS games that heavily use Lua. No problem at all, it's easy to get in.
Klaim