Hello
I'm using the co-routines example to do a little testing with AngelScript. I'm Using Code::Blocks + MinGW to compile.
I'll try to explain my problem as clear as possible... Basically, the script returns with code 3 (asEXECUTION_EXCEPTION) as soon as i try to run any mothod of an instantiated object.
Here is what i have:
First of all, there is a small virtual class which is supposed to handle input:
class ygi_input
{
public:
virtual ~ygi_input () {};
virtual void clear () = 0;
virtual bool load (const string FileName, const string Player, const string Name, const string Default = "") = 0;
virtual bool save (const string FileName) = 0;
/*
some other methods...
*/
virtual bool waspressed (const sint32 FramesBack) = 0;
virtual bool wasreleased (const sint32 FramesBack) = 0;
virtual sint32 value () = 0;
};
there is an inherited class which implements all the virtual functions from this base class, but the application only uses the main class via pointers... somthing like:
ygi_input MyInput = CreateInputClass ();
ygi_input *CreateInputClass ()
{
//DerivedClass is something like DerivedClass : public ygi_input
DerivedClass *Cls = new DerivedClass;
return (ygi_input *) Cls;
}
So, what i did is use the Coroutines example which comes with AngilScript and alther it a little bit to include handling of this input class.
First, i created some basic functions for behaviour and some others for testing...
map <ygi_input *, int> RefCounter;
ygi_input *InputFactory ()
{
ygi_input *Ret = ygi_createinput ();
if (Ret != NULL)
RefCounter [Ret] = 1;
return Ret;
}
void InputAddRef (ygi_input *Obj)
{
RefCounter [Obj] ++;
}
void InputRemRef (ygi_input *Obj)
{
RefCounter [Obj] --;
if (RefCounter [Obj] == 0)
{
ygi_releaseinput (Obj);
}
}
bool InputLoad (ygi_input *Obj, string A, string B, string C, string D)
{
return Obj->load (A, B, C, D);
}
bool InputPressed (ygi_input *Obj, sint32 Frms)
{
return Obj->waspressed (Frms);
}
void InputClear (ygi_input *Obj)
{
Obj->clear ();
}
And altered the ConfigureEngine function a little bit to add the object to the script:
// [...]
RegisterScriptAny(engine);
r = engine->RegisterObjectType("ygi_input", sizeof(ygi_input), asOBJ_REF); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ygi_input", asBEHAVE_FACTORY, "ygi_input @f()", asFUNCTION(InputFactory), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ygi_input", asBEHAVE_ADDREF, "void f()", asFUNCTION(InputAddRef), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ygi_input", asBEHAVE_RELEASE, "void f()", asFUNCTION(InputRemRef), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ygi_input", "bool load (string ∈, string ∈, string ∈, string ∈)", asFUNCTION(InputLoad), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectMethod("ygi_input", "bool waspressed (const int)", asMETHODPR(ygi_input, waspressed, (const sint32), bool), asCALL_THISCALL); assert( r >= 0 );*/
r = engine->RegisterObjectMethod("ygi_input", "void clear ()", asFUNCTION(InputClear), asCALL_GENERIC); assert( r >= 0 );
// [...]
I can create object of type "ygi_input" in the scripts, but, as soon as y try to call any of the methods clear, load or waspressed, the (*currentCtx)->Execute() function returns with code 3, which the .h file says is asEXECUTION_EXCEPTION.
I tried with many different ways to register the method but all of them took me to the same problem :(
Any ideas or help...?