Script evaluation

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums

Wich is the best language?

Lua
15
38%
Python
6
15%
Ruby
1
3%
JavaScript
2
5%
GameMonkey
2
5%
Other (specify wich language)
10
25%
I have to write my own scripting language (lol)
4
10%
 
Total votes: 40

conallmmcg
Posts: 23
Joined: Sun Oct 19, 2008 2:35 pm

Post by conallmmcg »

@lefticus

i'm not really an experienced programmer so i chose chaiscript simply because it was seriously easy to expose functions and even classes in comparison to the other languages (lua boost::python etc).

angelscript was easy but when it came to exposing classes it was a headache.
you can follow the error messages to see the problems, but when it gives you just "error" it doesn't give you much to go on.

i'm very impressed with how easily chaiscript works with C++, thanks btw!
i spent approx two hours using angelscript and reading the docs scratching my head, remembered i always wanted to try chaiscript and within 15-20 minutes i had an irrlicht window rendering using a script.

only problem i've come across is exposing overloaded functions.
the example app shows the use of typedefs to work around it, is there any other way to do this in the works?

oh and what's the performance/overhead like vs lua/boost::python/angelscript etc?
lefticus
Posts: 6
Joined: Mon Mar 21, 2011 8:20 pm
Contact:

Post by lefticus »

conallmmcg wrote:@lefticus
i'm very impressed with how easily chaiscript works with C++, thanks btw!
i spent approx two hours using angelscript and reading the docs scratching my head, remembered i always wanted to try chaiscript and within 15-20 minutes i had an irrlicht window rendering using a script.

only problem i've come across is exposing overloaded functions.
the example app shows the use of typedefs to work around it, is there any other way to do this in the works?

oh and what's the performance/overhead like vs lua/boost::python/angelscript etc?
Thanks for the awesome kudos.

The method that works most of the time is to provide the function signature as the template argument to the fun() call on the registration line:

Code: Select all

//From code I recently did for a client.
//This registers the particular from_string overload of boost::asio:ip::address that we want
//And by giving it the name of the class ("address") makes it appear as 
//another constructor overload in ChaiScript :)

using namespace boost::asio::ip;
chai.add(chaiscript::fun<address (const std::string &)>(&address::from_string), "address");
There are times when you may have to cast the function first, as you pointed out, because the compiler will get confused as to which overload you want.

I've been trying to keep up with stack overflow (there's the very rare question about ChaiScript there) and the ChaiScript forums if you have more questions.

Thanks,
Jason
viejodani
Posts: 32
Joined: Tue Nov 10, 2009 3:09 pm

Post by viejodani »

I chose Squirrel, Left4Dead2 uses it and a Chinese online game uses it as well (with the Squirrel Creator a a collaborator).

So far I have been impressed by the new changes and the binding is not that bad at all. Kudos for Squirrel. I'm sold
-- Never lose your sense of wonder --
lefticus
Posts: 6
Joined: Mon Mar 21, 2011 8:20 pm
Contact:

Post by lefticus »

viejodani wrote:I chose Squirrel, Left4Dead2 uses it and a Chinese online game uses it as well (with the Squirrel Creator a a collaborator).

So far I have been impressed by the new changes and the binding is not that bad at all. Kudos for Squirrel. I'm sold
I really don't want to keep butting in on this conversation, but I would love to take advantage of the opportunity to see what people are looking for in a scripting engine.

Taking Squirrel (I was not yet familiar with it) the docs have these examples:

To Register A Function

Code: Select all

SQInteger register_global_func(HSQUIRRELVM v,SQFUNCTION f,const char *fname)
{
    sq_pushroottable(v);
    sq_pushstring(v,fname,-1);
    sq_newclosure(v,f,0,0); //create a new function
    sq_createslot(v,-3); 
    sq_pop(v,1); //pops the root table    
}
(Interestingly the example doesn't return a value even though the function does)

Additionally, the requirement is made that all functions registered must have the same signature, namely:

Code: Select all

typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM);
To Call A Function

Code: Select all

sq_pushroottable(v);
sq_pushstring(v,“foo”,-1);
sq_get(v,-2); //get the function from the root table
sq_pushroottable(v); //’this’ (function environment object)
sq_pushinteger(v,1);
sq_pushfloat(v,2.0);
sq_pushstring(v,”three”,-1);
sq_call(v,4,SQFalse);
sq_pop(v,2); //pops the roottable and the function
Taking this example, which does not initialize the squirrel runtime, and converting it to an entire ChaiScript example:

Code: Select all

#include <chaiscript/chaiscript.hpp>
#include <sstream>
#include <string>

std::string foo(int i, double d, const std::string &str)
{
  std::stringstream ss;
  ss << i << " " << d << " " << str;
  return ss.str();
}

int main()
{
  using namespace chaiscript;
  ChaiScript chai;
  chai.add(fun(&foo), "foo");
  std::string retval = chai.eval<std::string>("foo(1, 2.0, "three")");
}
That's it, the entire example creates a function, registers it, automatically handles type safety in function calling, and extracts the return value from the script into retval.

Does Squirrel offer better methods of calling into it than I see in the docs, or am I overlooking something?

I'm very interested in any feedback that anyone has.

Thanks,
Jason
conallmmcg
Posts: 23
Joined: Sun Oct 19, 2008 2:35 pm

Post by conallmmcg »

lol this is why i chose chaiscript myself.
i wanted to implement scripting, but i kept wasting so much time with binding and strange errors. (esp boost::python)

but chaiscript *just works*
i would recommend anybody following this thread to at least try it.
i bet its stupidly easier than most script engines u are used to.

i don't wanna come off as a fanboi or something, s'pose i'm just happy with my choice :)
lefticus
Posts: 6
Joined: Mon Mar 21, 2011 8:20 pm
Contact:

Post by lefticus »

conallmmcg wrote:i don't wanna come off as a fanboi or something, s'pose i'm just happy with my choice :)
We do have a part of the site dedicated to projects that use chaiscript .... but no one has submitted any links. Let me know if you are interested. It'd be great to have some projects listed.
viejodani
Posts: 32
Joined: Tue Nov 10, 2009 3:09 pm

Post by viejodani »

@lefticus.

I don't use that kind of binding with squirrel. Instead I use squirrel scripts to access classes and functions written in C/C++ using sqPlus.

Chaiscript is not bad at all. Just one question, how you compile a Chaiscript file to a binary and load it to your app? I compile a Squirrel .nut file to an .sq and load it.

thanks
-- Never lose your sense of wonder --
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Post by hendu »

I really don't want to keep butting in on this conversation, but I would love to take advantage of the opportunity to see what people are looking for in a scripting engine.
A pretty hard req for me is usability from C. It sounds like chaiscript is C++-only.
lefticus
Posts: 6
Joined: Mon Mar 21, 2011 8:20 pm
Contact:

Post by lefticus »

hendu wrote:
I really don't want to keep butting in on this conversation, but I would love to take advantage of the opportunity to see what people are looking for in a scripting engine.
A pretty hard req for me is usability from C. It sounds like chaiscript is C++-only.
That's true, it's 100% C++. Since C doesn't have templates, you cannot do the compile time type resolution I'm doing and you are kind of stuck with the lua model of integration. Even SWIG won't work for you, as it generates C++ code.
lefticus
Posts: 6
Joined: Mon Mar 21, 2011 8:20 pm
Contact:

Post by lefticus »

viejodani wrote:@lefticus.

I don't use that kind of binding with squirrel. Instead I use squirrel scripts to access classes and functions written in C/C++ using sqPlus.

Chaiscript is not bad at all. Just one question, how you compile a Chaiscript file to a binary and load it to your app? I compile a Squirrel .nut file to an .sq and load it.

thanks
Ah, so there is an easier way of accomplishing the binding. We don't currently support any kind of compilation, you just load the .chai source when you want it:

Code: Select all

chai.eval_file(filename)
Performance gains would likely be minimal for us with compilation into some byte code, but it would allow for some script obfuscation if that was the goal.
RVM
Posts: 13
Joined: Sun Mar 27, 2011 6:14 pm
Location: France
Contact:

Post by RVM »

Here you can find a Game Scripting Languages Comparaison who talk about AngelScript, GameMonkey, Lua, Pawn, Squirrel and TinyScheme.

Edit : You can see at http://pastie.org/1721408 too
LizardGamer
Posts: 83
Joined: Fri May 28, 2010 8:59 am
Location: Perth, Australia

Post by LizardGamer »

Kojack wrote:Lua has quite a track record of success in games, and it's small and fast.

My favourite scripting language though is Falcon.
http://www.falconpl.org/index.ftd?page_id=facts
It's a bit like lua (I was able to convert a lua script (full logic for a game) to falcon with only minor changes to syntax), but it's got a lot more features.

Documentation for it tends to be the downside.
But I've heard that it's hard to port lua code to C++ and back, wouldn't that have a major effect on how the game would be programmed?

Plus Lua uses it's on Syntax, whilst other programming languages (Not all) use similar Syntax's to C/C++
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

LizardGamer wrote:
Kojack wrote:Lua has quite a track record of success in games, and it's small and fast.

My favourite scripting language though is Falcon.
http://www.falconpl.org/index.ftd?page_id=facts
It's a bit like lua (I was able to convert a lua script (full logic for a game) to falcon with only minor changes to syntax), but it's got a lot more features.

Documentation for it tends to be the downside.
But I've heard that it's hard to port lua code to C++ and back, wouldn't that have a major effect on how the game would be programmed?

Plus Lua uses it's on Syntax, whilst other programming languages (Not all) use similar Syntax's to C/C++
Why would you even want to port LUA code to C++?
The entire idea behind LUA and other scripting languages is that you can separate your game logic from your main codebase so you don't need to recompile your entire application whenever you make the smallest change in your game logic, if you ever find yourself porting LUA code over to C++ you should be really questioning yourself about what you're trying to accomplish
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

If one feels the need to port code from Lua(no acronym) to a natively compiled language for performance issues, then one ought to use LuaJIT instead of the original interpreter. If one still have performance issues, then one should reconsider the design/architecture of their system/pipeline/game, an/or ask the question that Radukalizm raises.
If for you an alien syntax is reason enough not to use a language, then your not judging the language by its merits but with your personal taste. your loss ;)
If you don't have anything nice to say, don't say anything at all.
LizardGamer
Posts: 83
Joined: Fri May 28, 2010 8:59 am
Location: Perth, Australia

Post by LizardGamer »

Who ever wrote this, I can't be bothered writing your name wrote: Why would you even want to port LUA code to C++?
The entire idea behind LUA and other scripting languages is that you can separate your game logic from your main codebase so you don't need to recompile your entire application whenever you make the smallest change in your game logic, if you ever find yourself porting LUA code over to C++ you should be really questioning yourself about what you're trying to accomplish
I'm not sure, but I didn't know if this could impact your game or not.

I got it from here: http://blog.wolfire.com/2010/01/Choosin ... g-language

But I'm sort of choosing from Ruby(not to sure), AngelScript(I like what I see), and Chai/Chia script(Not to sure but looks good).

I'm just trying to find one that is easy to learn, good speed (don't care if it's not THE fastest), easy to script for a game, and easy to connect/attach/manage to/with my engine.
Post Reply