Key elements of choosing a scripting language
Lets analyze what are the key elements of choosing a scripting language for a game:
- Glue code. The embedding is a process that, unfortunately, comes with additional development cost. The developer needs to expose (aka wrap) classes and functions by writing glue code. This is not an easy task and it varies from API to API. For example squirrel was designed to be an embedded language in games and its fairly easy to write glue code. Python on the other hand is not. Using python C API is very unproductive.
- Speed. Some interpreter implementations offer faster responsiveness over others. For example Google’s V8 engine offers JIT (just in time) compilation, a feature that made Google’s Chrome one of the fastest browsers out there.
- Platform support. The language binaries/libraries should be portable among popular gaming platforms like PC and consoles. In most cases this is not a problem because most of the interpreters are written in C/C++ which makes them fairly portable. There is a big “but” though. Some interpreters support JIT compilation, a feature that implies generation of machine dependent code at runtime. One example is Google’s V8 again. In order to use V8 you have to build only 32bit executables of your application. Ok that not a big deal, the big deal is that the generated code is for x86 and ARM platforms and it wont run in console hardware without major modifications.
- Popularity: Being a popular language means that there are lots of tutorials, documentation and people who can help you. Some languages are fairly new like Squirrel and they lack excessive support. Its a risk to use a language and have to switch later because of lack of support.
Pros and cons of the tested implementations
Lets see what are the pros and cons of all these implementations:
- Lua: Fast, small memory footprint, very popular among game developers, moderate glue code writing, weird syntax (IMHO)
- Squirrel: Speed is undetermined, glue code writing is easy, designed for game embedding, not that many developers behind it
- Python: Not the fastest around, huge in non-game developers and popular among game developers, lots of glue code when using C API but very very easy with boost python
Why boost python?
After creating (and still creating) prototypes we choose boost python. Boost python is a very smart wrapper on top of Python’s C API that makes the writing of glue code very very easy. Python is the most popular scripting language around, it may be slower than lua but for the py3k (Python 3.x) there is a JIT compiler under development. On the downside, boost python is template oriented and most of the time you find yourself in front of compiler errors with obfuscated cause. Also the documentation is lucking.