this is my c++ code:
class Base {
public:
Base() {
_refCount = 1;
cout << "Base Create" << endl;
}
void addRef() {
_refCount++;
}
void release() {
_refCount--;
if (_refCount == 0) {
delete this;
}
}
void reciever(asIScriptObject *obj) {
cout << "???" << endl;
man = obj;
}
void active() {
cout << "??Active" << endl;
cout << (man == 0) << endl;
cout << "??Active" << endl;
}
private:
int _refCount;
asIScriptObject *man;
};
Base *Base_Factory() {
return new Base();
}
......
//---------------------------------------------------------
scriptEngine->RegisterObjectType("Base", 0, asOBJ_REF);
scriptEngine->RegisterObjectBehaviour("Base",asBEHAVE_FACTORY, "Base@ f()", asFUNCTION(Base_Factory), asCALL_CDECL);
scriptEngine->RegisterObjectBehaviour("Base", asBEHAVE_ADDREF, "void f()", asMETHOD(Base, addRef), asCALL_THISCALL);
scriptEngine->RegisterObjectBehaviour("Base", asBEHAVE_RELEASE, "void f()", asMETHOD(Base, release), asCALL_THISCALL);
//---------------------------------------------------------
CScriptBuilder builder;
r = builder.StartNewModule(scriptEngine, "MyModule");
int isOK = builder.AddSectionFromFile("init.as");
asIObjectType *type = scriptEngine->GetObjectTypeByName("Human");
cout << "type == " << (type == 0) << endl;
//r = builder.AddSectionFromFile("test.as");
r = builder.BuildModule();
scriptEngine->RegisterObjectMethod("Base", "void reciever(Human @in)", asMETHOD(Base, reciever), asCALL_THISCALL);
scriptEngine->RegisterObjectMethod("Base", "void active()", asMETHOD(Base, active), asCALL_THISCALL);
........
and in my init.as script code:
class Human {
Human(){}
}
but it is still report a error:
Failed in call to function 'RegisterObjectMethod' with 'Base' and 'void reciever(Human @in)' (code: -10)
why ? may it must to reciever a interface nor a script class?