Hello, I've been struggling with registering/binding my class with AngelScript for the past few days, and I've went over the documentation a fair amount of times, but I haven't figured out the problem. I have a class like this:
class ENGINE_EXPORT GameObject : public Object
{
friend class Level;
public:
GameObject(uint32 id, String name, bool isStatic = false);
int addRef();
int release();
protected:
~GameObject();
Level* mCreator;
int mRefCount;
};
And I'm registering it like this:
void bindGameObject(asIScriptEngine* engine)
{
int r;
r = engine->RegisterObjectType("GameObject", 0, asOBJ_REF);
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 );
r = engine->RegisterObjectMethod("GameObject", "const string& getName()", asMETHOD(GameObject, getName), asCALL_THISCALL); assert( r >= 0 );
}
The game objects are created by a class "Level" which is registered like so:
void bindLevel(asIScriptEngine* engine)
{
engine->RegisterObjectType("Level", 0, asOBJ_REF | asOBJ_NOHANDLE);
int r = engine->RegisterObjectMethod("Level", "void createSky()", asMETHOD(Level, createSky), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("Level", "const string& getName()", asMETHOD(Level, getName), asCALL_THISCALL); assert( r >= 0 );
//r = engine->RegisterObjectMethod("Level", "bool getGameObject(const string &in, GameObject &out)", asMETHODPR(Level, getGameObject, (const String&, GameObject&), bool), asCALL_THISCALL); assert (r >= 0);
r = engine->RegisterObjectMethod("Level", "const GameObject @+ getGameObject(const string &in name)", asMETHOD(Level, getGameObject), asCALL_THISCALL); assert( r >= 0 );
// int r = engine->RegisterObjectMethod("")
}
The problem is with the getGameObject function, it's declared on the C++ like this:
// String is just a typedef of std::string.
GameObject* getGameObject(const String& name);
And in my actual script I have this:
void testGet()
{
GameObject@ obj = level.getGameObject("CamObj");
}
But I get "Error Compiling void testGet()".
Any ideas as to where my problem is ? (Sorry for the spammy code)
BTW - The addRef and release functions are taken from the Game sample, as is the way of registering.