Saturday, October 08, 2011

Embeddable Scripting Languages for Games

I've thought about using Lua for game scripting (easier, more flexible, less freaky for others than our GameForth). Lua is used in lots of games, such as World of Warcraft, Baulder's Gate, Angry Birds, Civilization V, Escape from Monkey Island, Far Cry, Lego Universe, Homeworld 2, Plants vs. Zombies, The Sims 2: Nightlight, SimCity 4 ... [1]

Anyway, assuming a need for one of my games, I saw another embeddable scripting language mentioned in a Linux magazine called Squirrel.

It seems to have the following advantages that are good from my perspective:
  • More C-like syntax than Lua (although Lua syntax is not too bad - a bit BASIC or Pascal like)
  • Classes supported by default (classes can be implemented relatively easily in Lua with tables)

Squirrel has been used for Code::Blocks, Final Fantasy Crystal Chronicles: My Life as a King, Left 4 Dead 2 and Portal 2. [2]

Anyway a couple of links for Squirrel:

 function factorial(x)
if (x == 0) {
return 1;
else {
return x * factorial(x-1);

A couple of links for Lua

  function factorial(n)
if n == 0 then
return 1
return n * factorial(n - 1)

A comparison:

Also this:

"The Python/C API manual is longer than the whole Lua manual (including the Lua/C API).

Another reason for Lua is the built-in support for coroutines (co-operative multitasking within the one OS thread). It allows one to have like 1000's of seemingly individual scripts running very fast alongside each other. Like one script per monster/weapon or so."


Squirrel has cooperative threads(co-routines) ... according to

Other Choices

Another one is Angelscript (discussion here )


"Efforts have been made to let it call standard C functions and C++ methods with no need for proxy functions. The application simply registers the functions, objects, and methods that the scripts should be able to work with and nothing more has to be done with your code. The same functions used by the application internally can also be used by the scripting engine, which eliminates the need to duplicate functionality."

Angelcode also has co-routines -

Obviously things like Python (and stackless-Python) are technically possible to be used as embedded languages, and some people do use them in this fashion - but for games they've been seen as too heavy weight.


Newer›  ‹Older