// AngelScript Code:
ZedScriptW p(ptrToZedEntityID1);
ZedScriptW s(ptrToZedEntityID2);
This part seems to work.
// C++
r = engine->RegisterObjectType("ZedScriptW", sizeof(ZedScriptW), asOBJ_VALUE|asOBJ_APP_CLASS|asOBJ_APP_CLASS_CONSTRUCTOR|asOBJ_APP_CLASS_DESTRUCTOR); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ZedScriptW", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ZedScriptW_Constructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ZedScriptW", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(ZedScriptW_Destructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
However I can't figure out how to create a constructor that accepts multiple parameters.
This is my attempt
// C++
r = engine->RegisterObjectBehaviour("ZedScriptW", asBEHAVE_CONSTRUCT, "void f(ZedEntityID @)", asFUNCTIONPR(ZedScriptW_Constructor_ZedEntityID, (ZedScriptW*, ZedEntityID*), void), asCALL_CDECL_OBJLAST); assert( r >= 0 );
This is the code for the constructor that takes a parameter. The function is called when I run it, but ownerID points to garbage.
// C++
void ZedScriptW_Constructor_ZedEntityID(ZedScriptW *memory, ZedEntityID *ownerID)
{
new(memory) ZedScriptW();
if (ownerID)
memory->SetComponent(ownerID->GetOwner());
}
Can anyone help?
Edit:
I think I have figured it out while writing this post. asCALL_CDECL_OBJLAST is the hint. So I have swapped the params around.
r = engine->RegisterObjectBehaviour("ZedScriptW", asBEHAVE_CONSTRUCT, "void f(ZedEntityID @)", asFUNCTIONPR(ZedScriptW_Constructor_ZedEntityID, ( ZedEntityID*, ZedScriptW*), void), asCALL_CDECL_OBJLAST); assert( r >= 0
void ZedScriptW_Constructor_ZedEntityID(ZedEntityID *ownerID, ZedScriptW *memory)
Hopefully all of the above is correct. If not please let me know.