Another day, another problem
i have this object (not a POD)
r = engine->RegisterObjectType("JsVariable", sizeof(JsVariable), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK); assert( r >= 0 ); // CDAK stands for class constructor assignment and copy constructor as i understand
// destructor
r = engine->RegisterObjectBehaviour("JsVariable", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(JsVariable::JsVariableDestructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
// default constructor
r = engine->RegisterObjectBehaviour("JsVariable", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(JsVariable::JsVariableDefaultConstructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
// copy constructor. not called
r = engine->RegisterObjectBehaviour("JsVariable", asBEHAVE_CONSTRUCT, "void f(const JsVariable &in)", asFUNCTION(JsVariable::JsVariableCopyConstructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
// another constuctor
r = engine->RegisterObjectBehaviour("JsVariable", asBEHAVE_CONSTRUCT, "void f(float)", asFUNCTION(JsVariable::JsVariableFloatConstructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
// another constuctor
r = engine->RegisterObjectBehaviour("JsVariable", asBEHAVE_CONSTRUCT, "void f(const string &in)", asFUNCTION(JsVariable::JsVariableStringConstructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
// another constuctor
r = engine->RegisterObjectBehaviour("JsVariable", asBEHAVE_CONSTRUCT, "void f(bool)", asFUNCTION(JsVariable::JsVariableBoolConstructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
// == operator
r = engine->RegisterObjectMethod("JsVariable", "bool opEquals(const JsVariable &in) const", asFUNCTION(JsVariable::JsVariableEquals), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
I create object as a part of CScriptArray
asIObjectType* t = ScriptManager::getSingletonPtr()->engine->GetObjectTypeById(ScriptManager::getSingletonPtr()->engine->GetTypeIdByDecl("array<JsVariable>"));
CScriptArray* arr = new CScriptArray(1, t); // default constructor successfully called.
JsVariable js = JsVariable((string)"test !");
arr->SetValue(0, &js);
when this line hits on scriptarray.cpp
objType->GetEngine()->CopyScriptObject(ptr, value, subTypeId);
i expect copy constructor to be called.
instead none of the constructors called. JsVariable is passed as it's created by CScriptArray* arr = new CScriptArray(1, t); . (default constructor)
copy constructor is this.
static void JsVariableCopyConstructor(const JsVariable &other, JsVariable *self)
{
new(self) JsVariable(other);
}
script function called is this (not really much related to question, but i may be wrong)
void UIOnCallback(string funcname, array<JsVariable> @arr) // arr is passed here correct. JsVariables come empty (default constructor), array length is correct
{
//do stuff
}
i kinda post a lot of code. I just want to clear the issue as it is.
i feel like i miss something very simple. but it's been 4 hours since i started staring at it.
why does not the copy constructor called?
thank you for your time