Original Post
Hi Everybody! I am playing with AngelScript for a few days and I really like it (especially how easy it it so register things...) Now I try to integrate AS with my game engine. I have C++ class called GameObject, I am going to register it as a reference type eg.: is it possible to extend this new AngelScript type with scripted member methods? I want to script behavior of my class eg. AngelScript code: so I can call Tick method on my GameObject instance reference (I want to avoid creating separate script object that handles scripting on my GameObject)... a pseudo code for that may look like: In general: is there any way to make "this" in script function (function compiled with script builder) point to registered c++ type instance? Kind Regards Tristan
r = engine->RegisterObjectType("GameObject", 0, asOBJ_REF); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("GameObject", asBEHAVE_ADDREF, "void f()", asMETHOD(GameObject,AddRef), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("GameObject", asBEHAVE_RELEASE, "void f()", asMETHOD(GameObject,Release), asCALL_THISCALL); assert( r >= 0 );
class GameObject
{
void Tick(float deltaTime)
{
this.MoveX(10); // "this" points to c++ registered GameObject type
}
};
asIScriptFunction *outFunc;
module->CompileFunction("GameObject.as", code, &outFunc);
engine->RegisterObjectMethod("GameObject", outFunc);