Advertisement Jump to content
Sign in to follow this  
John Schultz

Moving from Lua (LuaPlus) to Squirrel (SqPlus)

This topic is 4877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently switched from Lua (LuaPlus) to Squirrel (SqPlus). While Squirrel does not yet have a powerful template wrapper, using SqPlus only requires simple stubs to be created to exchange arguments (type checking is automatically performed (set up during binding (one line of code)). While Lua and Squirrel are faster/slower for different operations (tables/arrays, etc.), Squirrel will be much faster if scripting is complicated/large enough that garbarge collection comes into play: standard Lua will grind to a halt during garbage collection. LuaPlus, in addition to adding an excellent template system, adds reference counting. Squirrel's author ((commercial game) FarCry scripting engine developer) started modifying Lua to add reference counting but went on to create a new language (uses Lua's excellent table design/code). Syntax and language-design-wise, I much prefer Squirrel over Lua (closer to C/C++, has native class support (similar to Java/javascript), and many other advanced features). Lua's advantage is that it has been around longer (Squirrel is only 2 years old), and has a great deal of documentation (and many template wrappers available). My decision to switch to Squirrel was based on the improved language design over Lua, reference counting, and (relative) ease of understanding/tracing the core compiler/runtime code (including making quick tweaks in a short amount of time). I have written some code to make integrating Squirrel easier: see SqPlus here. Comparison of LuaPlus and SqPlus binding:
// LuaPlus:



LuaPlus creates all the necessary hooks/callback so that Lua script can access vars & call functions via the names in quotes. No other code is required: it's very fast/easy to bind objects (type checking is also automatically performed).

// Squirrel (with SqPlus):


    SquirrelVM::CreateFunctionGlobal("func1",func1Stub,"t"); // table arg
    SquirrelVM::CreateFunctionGlobal("func2",func2Stub,"s"); // string arg
    SquirrelVM::CreateFunctionGlobal("func3",func3Stub,"si"); // string, int args
    SquirrelVM::CreateFunctionGlobal("func4",func4Stub,"ssbf"); // strings, bool,float
    SquirrelVM::CreateFunctionGlobal("func5",func5Stub,"sssf"); // strings, float
    SquirrelVM::CreateFunctionGlobal("func6",func6Stub,"ssiff"); // strings, int, floats
    SquirrelVM::CreateFunctionGlobal("func7",func7Stub); // no args.

// SqPlus currently requires small stubs be created. Examples:

// Named arguments passed via table:

  static int initTerrain(HSQUIRRELVM v) {
    StackHandler sa(v);
    HSQOBJECT htable = sa.GetObject(2);
    SquirrelObject table(htable);
    flt cellSize = 7000.f;
    int cellWidth=6,cellHeight=12;
    if (table.Exists("cellSize"))   cellSize   = table.GetFloat("cellSize");
    if (table.Exists("cellWidth"))  cellWidth  = table.GetInt("cellWidth");
    if (table.Exists("cellHeight")) cellHeight = table.GetInt("cellHeight");
    return sa.Return(true);
  } // initTerrain

// Fixed arguments: automatically type checked (set up during binding):

  static int setEventTriggerTimeSequence(HSQUIRRELVM v) {
    StackHandler sa(v);
    const char * rigidBodyEventTrigger = sa.GetString(2);
    const char * rigidBodyControllee   = sa.GetString(3);
    int repeatCount                    = sa.GetInt(4);
    float startTime                    = sa.GetFloat(5);
    float endTime                      = sa.GetFloat(6);
    int res = r4d->setEventTriggerTimeSequence(rigidBodyEventTrigger,rigidBodyControllee,repeatCount,startTime,endTime);
    return sa.Return(res);
  } // setEventTriggerTimeSequence

Squirrel's author is currently working on a cross platform, portable remote debugger using Java and Eclipse (Squirrel should work on all platforms (tested on Win32/*nix)). I have been experimenting with scripting languages since 2000 (starting with Lua): once the remote debugger is available, Squirrel will be one of the best scripting languages for game applications (a good/complete template wrapper would make it even better).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!