Scripting engine?

hey juce folks…
looking in the public share you’ll find a gift!
is just a proof of a concept and very very lazy coding…
but is a starting point !
same place


i slightly modified the scriptengine to be extensible. i’m running in winzoze,
and would like to now if there are compiling problems on other platforms.


Never used Angelscript, used to Python and LUA. From the examples it appears that it only supports linking methods to global functions, can you map a class into it?

yeah of course. but don’t support perfectly (it can be simulated tho) inheritance, pure virtuals or static methods. i prefer angelscript over lua or python because it have a more c/c++ like syntax.
here is an example directly from angelscript code. is a simple string. but here u have the tipical setup for exporting objects to the script. type registering, constructor/destructor definition, operator exporting, global and object behaviours and methods. very powerful and exporting a class is very easy. i’ll do a go on exporting some methods from the Component class.

[code]// Register the type
r = engine->RegisterObjectType("string", sizeof(asCScriptString), asOBJ_CLASS_CDA);

// Register the object operator overloads
// Note: We don't have to register the destructor, since the object uses reference counting
r = engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT,  "void f()",                    asFUNCTION(ConstructString), asCALL_CDECL_OBJLAST);
r = engine->RegisterObjectBehaviour("string", asBEHAVE_ADDREF,     "void f()",                    asMETHOD(asCScriptString,AddRef), asCALL_THISCALL);
r = engine->RegisterObjectBehaviour("string", asBEHAVE_RELEASE,    "void f()",                    asMETHOD(asCScriptString,Release), asCALL_THISCALL);
r = engine->RegisterObjectBehaviour("string", asBEHAVE_ASSIGNMENT, "string &f(const string &in)", asMETHODPR(asCScriptString, operator =, (const asCScriptString&), asCScriptString&), asCALL_THISCALL);
r = engine->RegisterObjectBehaviour("string", asBEHAVE_ADD_ASSIGN, "string &f(const string &in)", asMETHODPR(asCScriptString, operator+=, (const asCScriptString&), asCScriptString&), asCALL_THISCALL);

// Register the global operator overloads
// Note: We can use std::string's methods directly because the
// internal std::string is placed at the beginning of the class
r = engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL,       "bool f(const string &in, const string &in)",    asFUNCTIONPR(operator==, (const string &, const string &), bool), asCALL_CDECL);
r = engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL,    "bool f(const string &in, const string &in)",    asFUNCTIONPR(operator!=, (const string &, const string &), bool), asCALL_CDECL);
r = engine->RegisterGlobalBehaviour(asBEHAVE_LESSTHAN,    "bool f(const string &in, const string &in)",    asFUNCTIONPR(operator <, (const string &, const string &), bool), asCALL_CDECL);
r = engine->RegisterGlobalBehaviour(asBEHAVE_GREATERTHAN, "bool f(const string &in, const string &in)",    asFUNCTIONPR(operator >, (const string &, const string &), bool), asCALL_CDECL);
r = engine->RegisterGlobalBehaviour(asBEHAVE_ADD,         "string@ f(const string &in, const string &in)", asFUNCTIONPR(operator +, (const asCScriptString &, const asCScriptString &), asCScriptString*), asCALL_CDECL);

// Register the index operator, both as a mutator and as an inspector
r = engine->RegisterObjectBehaviour("string", asBEHAVE_INDEX, "uint8 &f(uint)", asFUNCTION(StringCharAt), asCALL_CDECL_OBJLAST);
r = engine->RegisterObjectBehaviour("string", asBEHAVE_INDEX, "const uint8 &f(uint) const", asFUNCTION(StringCharAt), asCALL_CDECL_OBJLAST);

// Register the object methods
r = engine->RegisterObjectMethod("string", "uint length() const", asMETHOD(string,size), asCALL_THISCALL);


have you tried to embed lua scripting into juce ? i would like to know your results. :wink: i’m really interested in having very fast and easy scripting to embed and with the less efforts in scripting itself.


I use lua to bind things quite often, although I’ve rarely used it myself, I just set it up for others. I have not put lua into juce, if you just want a basic scripting engine using lua that would be very little and simple code, then I could do it if I get time this weekend. However, if you wanted to be able to do things like create components, then it becomes more interesting. Lua is made for speed and quick calculations and function, ergo, it has no class support, although you can emulate it with tables. Do you want a basic scripting engine to do stuff, or do you want it to be integrated into juce, as in being able to write your entire program in lua, the latter would take quite a bit more time to bind everything.

If you want classes and full features, you can’t beat python, it is slower then lua, but when you really need full class and binding support, it’s the way to go.

Don’t suppose you could post a quick snapshot of some angelscript code with comments explaing what does what and why? I’ve been looking for a reason to learn it.

By the way, I did some python bindings for JUCE (using SWIG). I gave up for a while and still have things to commit to the subversion repository. Maybe I’ll post some updates soon if anyone is interested …
For more info :

Yea, found it a while ago. Never have used SWIG, always have used boost, so I have yet to take a detailed look at it. I should sometime.

well, is just an experiment. i’m just experimenting to find the good things and bad bottlenecks on every technological solutions. for now i’ve experimented only with angelscript and gamemonkey. they’re my choice for a some facts, they’re extensible, they permit to publish objects (althought with some difficulties in the angelscript side) and functions in a easy manner, they’re used in games for controlling the logic and sometimes the ui behaviour (games menu selections and such), they are pretty fast, their codebase is stripped down, and more over they not need to have installed external dll or something.
my need is embed into juce a scripting engine without any kind of dependancies or whatever. with python i need to have it installed on the machine i run my app, and sometimes i can’t, or can’t force someone to install it. with lua i’ll see next days, i’m trying to embed it, and see what are the capabilities. embedding javascript could be another choice…
anyway swig can be setup for every scripting language ? or there are limitations ?

Well SWIG has a LOT of limitation.
It only support a given subset of languages and only fits well to do bindings of C/C++ libraries to be called from the target language runtime. The main advantage is that it’s easy to write an interface description file for a whole library : SWIG parses the headers and generates most of the embedding code automatically.

You can embed python into your application without needing external dll’s. That is often used in some games as well.

If we really want to have Python scripting, I recommend doing them with sip ( It’s dedicated to C++ – the Python Qt bindings are made with that.

actually my goals are the opposite, as i don’t want to bind juce to a scripting engine, i just want to bind (or embed) a scripting engine to juce itself. that’s why i’m developing angeljuice.

No, no Sip, just took a look at that, ugly…

I use boost::python, idiotically easy way to bind. I bound a library with over 500 function a few months ago in a single evening with boost::python.

I took a look an angelscript, too limiting, and scripting left quite a bit to be desired.

And yea, hate SWIG with a passion…

i idiotically hate python… :roll:

Really ? I’ve tried to use boost::python as an alternative to SWIG.
I first tried to use Pyste, which was not maintained anymore (acording to what I was told on the developer mailing list when I send a patch to fix a few bugs I found), because of important design flaws.
Then I turned to use pygccxml as I was told on the same list it was better. I encounterd some new problems which looked unsolvable and finaly went back to SWIG.

OvermindDL1 : Maybe I could send you what I did with boost so you could have a look …

I love python. :slight_smile:

And yea, I don’t use Pyste or whatnot, I use boost::python directly. Pyste was similier to (but easier to use then) swig, and I didn’t like that style at all in either case. Heard of pygccxml (or something similier), but never looked at it. I like boost::python directly, compared to angelscripting, lua scripting, squirrel scripting, the binds for it are so much easier then even the most simple binds for all of those.

Sure, post a link or pm a link or whatnot and I can look at it.