Skip to main content
GameDev.net gamedev.net
🔒 Locked

LUA, Squirrel, or AngelScript

Started by mazelle Aug 22, 2008 at 4:57 AM 3 replies 10.9k views
Original Post
mazelle
mazelle
Now I want to incorporate some scripting to may game base code for set-up stuff and AI logic. Which scripting language should I use? LUA - small, fast, has a track record - but hard to integrate with cpp (I'm looking into LuaBind here) Squirrel - nice language (supports OOP and cpp/java like syntax) - has no or limited track record - same concept as lua (are there wrapper code for squirrel?) AngelScript - nice language - easy to integrate - has no or limited track record Squirrel and AngelScript has better language constructs than LUA, but I'm still going for LUA because it's the mostly used scripting software (a plus in resume). Or am I wrong?
beun
beun
Well, you forgot the biggest difference between AngelScript vs. Lua/Squirrel: it isn't dynamically typed. In AS, you have to say int var1 = 5; instead of var1 = 5;

For me, the biggest advantage of AS is that you don't have to write proxy-functions. For example, for Lua, you have to write this in C(PP):
void DoSomething () // This function does something and you want to call it from Lua. It takes 0 arguments and returns nothing. {}// You have to write this useless function, because Lua needs it.int LUA_DoSomething (lua_State *L) {DoSomething();return 0;}// And then you have to register LUA_DoSomething:lua_register (L, "DoSomething", LUA_DoSomething);


In AS, you don't need LUA_DoSomething, you can directly register DoSomething:
engine->RegisterGlobalFunction("void DoSomething()", asFUNCTION(DoSomething), asCALL_CDECL);


This makes AS very productive: you don't need twice as much functions.
I think that for non-programmers Lua or Squirrel are the easiest ones. If you're a C(PP) programmer, maybe AngelScript resembles C(PP) closer. Squirrel resembles J(ava)Script (dynamic typing, and braces instead of "end"). Also, Lua doesn't have native OOP, and registering your own usertypes from your host program is a bit more complicated. In AS, you can register a standard CPP class as an object very easily.
Kylotan
Kylotan
It should be fairly simple in C++ to write a few templates that save you having to write those Lua proxy functions in 90% of cases. Something like this untested code:
void DoSomething (){}template<FN_PTR>int lua_wrap_void(lua_State *L){    (*FN_PTR)();    return 0;}lua_register (L, "DoSomething", lua_wrap_void<&DoSomething>);lua_register (L, "DoSomethingElse", lua_wrap_void<&DoSomethingElse>);lua_register (L, "DoAnotherThing", lua_wrap_void<&DoAnotherThing>);

You still write that useless function, but you only write it once for all functions with the same signature. In practice you end up writing about 4 or 5 of those and then you're done.
emeyex
emeyex
I've had good success with Squirrel so far.

SqPlus is a pretty easy to use code wrapper / binding system: clicky, though I actually found it pretty easy to do the bindings myself (so I haven't ended up using SqPlus).
mazelle
mazelle
I have chosen a scripting language.

What I want to know now is how much of a game to script?

My framework is a game state based one implemented as a stack with the top running the game loop (update, render). Game logic is implemented through events and event handlers (like inputs are translated to events, then some event handlers would handle the event; game events are fired, then event handlers would handle them). Each game state has it's own set of events and event handlers.

Is it advisable to move the handling of game states, events and event handlers to script?

The following are some constructs which I think should not be moved to scripting:
- collision detection
- rendering
- running of event handlers
- any list management code

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.