Friday, October 23, 2009

Picking a scripting language

We are planning to make the BitSquid engine largely scripting language agnostic. We will expose a generic scripting interface from the engine and it should be relatively easy to bind that to whatever scripting language you desire.

Still, we have to pick some language to use for our own internal projects and recommend to others. I'm currently considering three candidates:


  • Use regular C/C++ for scripting.
  • Run it dynamically either by recompiling and relinking DLLs or by running an x86 interpreter in the game engine and loading compiled libs directly.
  • + Static typing
  • + Syntax checking & compiling can be done with an ordinary compiler
  • + When releasing the game we can compile to machine code and get full native speed
  • - C is not that nice for scripting
  • - Huge performance differences between "fully compiled" and "interactive" code makes it difficult for the gameplay programmers to do performance estimates.
  • Lua has the same feature set as Python and Ruby, but is smaller, more elegant and faster.
  • Other scripting langues such as Squirrel, AngelScript offer reference counting and static typing, but are not as well known / used
  • + Dynamic, elegant, small
  • + Something of a standard as a game scripting language
  • + LuaJIT is very fast
  • - Non-native objects are forced to live on the heap
  • - Garbage collection can be costly for a realtime app
  • - Speed can be an issue compared to native code
  • - Cannot use LuaJIT on consoles
  • Use the Mono runtime and write scripts in C#, Boo, etc.
  • + Static typing
  • + Popular, fast
  • - Huge, scary runtime
  • - Garbage collection
  • - Requires license to run on console
  • - Can probably not JIT on console


  1. Lua all the way! We're about to ship a game using it on Xbox 360; by using it I mean 95% of the game code, including UI, is written entirely in Lua.

    We had some garbage collection issues - we had to add a touch of "manual garbage collection" here and there, which took a day or two of the final stretch - but that was all that it took memory-wise, after months and months of a room full of gameplay programmers banging away at code blissfully oblivious of the existence of such a thing as "memory". The speed of development is orders of magnitude higher than C++, and the code is considerably smaller.

    Performance is the main issue - we dedicated a full Xenon core to it, and got away with it - but on the PS3 that won't be possible. You either have to design around it - avoid game designs requiring lots of logic - or go to C++, where you lose the productivity gain.

    Our game is VERY simulation-heavy, IMHO higher than the vast majority of games on the market - so it was kind of a worst case; on the other hand, I understand how you, thinking only about an "engine", wouldn't want to limit potential customers. But the limit is very high - and the alternative is C++.

    What's especially great about Lua is the native support for coroutines, which allow you to implement what's called "latent functions" in UnrealScript - which make game logic code much more straightforward than the alternatives (e.g. state machines).

  2. You can also make your own scripting language that is job-centric and state-machine aware.

  3. Yes, I'm leaning towards Lua myself. It is what we used in the Grin engine and overall it did great things for us.

    The main problem we had with Lua at Grin was performance, especially in Terminator Salvation. We didn't run Lua on a separate core, and since we were shipping for PS3, that wouldn't really have helped. I think the performance problems might be a result of trying to do "too much" in Lua and that it might be mediated by moving more of the heavy-duty stuff to C++ and being a bit smarter about the C/Lua interface. But it is scary to end up in that situation late in a project. On the other hand, I guess you always end up with performance problems in gameplay code, no matter what the situation is.

    What is slightly scary is that when optimizing C++ code it usually boils down to a few bottleneck operations. You rewrite them and get a quick performance boost. With Lua, there weren't any real such choke points. It was just a matter of a slow (compared to C, not to other scripting languages) virtual machine running lots and lots of code, so there was no single place to do quick and easy optimizations.

    Memory might also be an issue, since we want a separate lua state per core (to allow fully multithreaded gameplay), that will multiply the lua runtime size by the number of cores. But I think we can solve that by keeping all the state data in C and just doing operations on it in Lua. (That also saves the trouble of synchronizing the Lua states.)

  4. At Unity we have very good experience with Mono. It gives us excelent programming languages and very good performance over interpreted languages.
    So if you get over the admittedly high startup costs, in terms of integration and understanding the code, there are many benefits.
    Also we get very good support from the Novell guys.

    You are velcome to contact us if yo need more info.

  5. Mix it C++ + javascript ..

  6. We all apprehend that Epson printer is a relatively relaxed and compactable printing tool canon printers are help you discover your paintings productiveness thru its wireless networking competencies. If you're searching Customer Care Support Services on your printer then you can visit our web websites. Thanks
    canon printer offline to online

  7. Follow the easy steps for HP LaserJet P1102W Setup. Reach the printer setup experts for HP LaserJet P1102w setup, if you face issues with setup.

  8. Canon MG3520 Wireless Setup is easy to do the process. Follow simple guidelines in an article for Canon MG3520 Setup. Reach our experts, in case of any issue.

  9. Most Brother printer models have mounted network adapters. You can link the Brother printer to your wifi instead of connecting the printer directly to your device and use it as a network tool. If you want to use the printer from multiple computers in your home or if all of your machines are laptops and you don't want to bother attaching and disconnecting the printer when you switch from room to room, this configuration is beneficial. Connect brother printer to wifi


  10. your post is very interesting to read.
    Thank you very much.This website has everything I need.

  11. Thank you for your article that is useful for me, and I will save the name of your blog, I will definitely return to read your new article.

  12. Thank for your writting. You have made it very clear that the problem is happening. I really like your way of thinking. Install Kaspersky already purchased

  13. Nice imformative blog.Thank you and waiting for your new post.

  14. I really like your post, I always like to read a quality content having accurate information regarding the subject. Thanks for sharing. It is such a very amazing

  15. Excellent and nice post. It will beneficial for everyone. Thanks for sharing such a wonderful post. To read more visit our post which link has been given below.visit:

  16. Great blog too very impressive! Excellent and nice post. This is such a great resource that you are providing and you give it away for free.I would like to thank you for the effort you have made in writing this article. visit: