Advertisement

References and uninstanciable objects

Started by August 03, 2008 08:38 AM
1 comment, last by SiS-Shadowman 16 years, 4 months ago
I've registered an object like this:

Engine->RegisterObjectType( "Helper", 0, asOBJ_REF );
Engine->RegisterObjectBehaviour("Helper", asBEHAVE_ADDREF, "void f()", asMETHOD(CHelper, AddRef), asCALL_THISCALL);
Engine->RegisterObjectBehaviour("Helper", asBEHAVE_RELEASE, "void f()", asMETHOD(CHelper, Release), asCALL_THISCALL);

// CHelper *GetHelper()
Engine->RegisterGlobalFunction( "Helper @GetHelper()", asFUNCTION( GetHelper ), asCALL_CDECL )


When I write a script like this:

int main()
{
    Helper m = GetHelper();
}


The build function fails with -1, but I don't get any compiler warnings. I then realized that I needed to make the variable a reference, but I wonder why the compiler doesn't tell me (I have set a message callback, but it isn't called). Did I do a mistake somewhere or is this a bug? Okay, I solved it, I used cdecl as the calling convention for a member method: changed it to thiscall, now the callback function does work. [Edited by - SiS-Shadowman on August 3, 2008 2:48:50 PM]
You should have gotten some compiler error. I need to look into it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
I do now, no need to look at it :)
I placed the wrong calling convention in the messagecallback registration, wich resulted in my callback never being called.

This topic is closed to new replies.

Advertisement