Hello!
I wanted to write code which will handle such operations in the script:
CSomeClass class;
class = Master.FindSub(...);
I don't know if I did that properly, because I'm receiving some not very pleasant errors. Here is what I did:
Master class:
class CMaster
{
public:
CMaster(){};
~CMaster(){};
CSomeClass FindSub( int index )
{
CSomeClass cl;
return cl;
}
};
Here I register CSomeClass:
r = ScriptEngine->RegisterObjectType("CSomeClass", sizeof(CSomeClass), asOBJ_CLASS_CDA);assert(r>=0);
r=ScriptEngine->RegisterObjectBehaviour("CSomeClass", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(Constructor, (CSomeClass*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
r=ScriptEngine->RegisterObjectBehaviour("CSomeClass", asBEHAVE_DESTRUCT, "void f()", asFUNCTIONPR(Destructor, (CSomeClass&), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
r=ScriptEngine->RegisterObjectBehaviour("CSomeClass", asBEHAVE_ADDREF, "void f()", asMETHOD(CSomeClass, AddRef), asCALL_THISCALL); assert(r >= 0);
r=ScriptEngine->RegisterObjectBehaviour("CSomeClass", asBEHAVE_RELEASE, "void f()", asMETHOD(CSomeClass, Release), asCALL_THISCALL); assert(r >= 0);
Here is it's declaration:
class CSomeClass
{
public:
CSomeClass(): refcount(1) {};
~CSomeClass()
{
}
void AddRef(){refcount++;}
void Release(){ if(--refcount == 0) delete this;}
private:
int refcount;
};
Here I register the CMaster class:
r = ScriptEngine->RegisterObjectType("CMaster",sizeof(CMaster), asCALL_CDECL);assert(r >= 0);
r = ScriptEngine->RegisterGlobalProperty("CMaster Master", (void*)&Master); assert(r>=0);
r = ScriptEngine->RegisterObjectMethod("CMaster", "CSomeClass FindSub(int index)", asMETHOD(CMaster,FindSub), asCALL_THISCALL);assert(r >= 0);
Then when I perform:
CSomeClass class;
class = Master.FindSub(...);
I get some heap allocation errors.
P.S. I hope I remembered to put everything that is of any use here.
Regards,
Black Dot