Script evaluation
-
- Posts: 23
- Joined: Sun Oct 19, 2008 2:35 pm
@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?
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?
Thanks for the awesome kudos.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?
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");
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
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.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
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
}
Additionally, the requirement is made that all functions registered must have the same signature, namely:
Code: Select all
typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM);
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
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")");
}
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
-
- Posts: 23
- Joined: Sun Oct 19, 2008 2:35 pm
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
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.
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
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 --
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.hendu wrote:A pretty hard req for me is usability from C. It sounds like chaiscript is C++-only.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.
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: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
Code: Select all
chai.eval_file(filename)
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
Edit : You can see at http://pastie.org/1721408 too
-
- Posts: 83
- Joined: Fri May 28, 2010 8:59 am
- Location: Perth, Australia
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?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.
Plus Lua uses it's on Syntax, whilst other programming languages (Not all) use similar Syntax's to C/C++
-
- Posts: 1215
- Joined: Tue Jan 09, 2007 7:03 pm
- Location: Leuven, Belgium
Why would you even want to port LUA code to C++?LizardGamer wrote: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?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.
Plus Lua uses it's on Syntax, whilst other programming languages (Not all) use similar Syntax's to C/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
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 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.
-
- Posts: 83
- Joined: Fri May 28, 2010 8:59 am
- Location: Perth, Australia
I'm not sure, but I didn't know if this could impact your game or not.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 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.