Advertisement

Class constructor/destructor registration for asCALL_GENERIC

Started by February 18, 2020 03:31 PM
2 comments, last by WitchLord 4 years, 9 months ago

I'm struggling registering class constructor and destructors following the example in “Registering a Value Type”. For,

r = m_pEngine->RegisterObjectType("Motor", sizeof(Motor), asOBJ_VALUE); assert(r >= 0);

The example implies I cannot register Motor::Motor(); that a “factory function” should be use? It looks like the example is registering a global Constructor(void *memory), not a class member. So I have,

void CallConstructor(void* memory)
{
	new(memory) Motor();
}

r = mpEngine->RegisterObjectBehaviour("Motor", asBEHAVE_CONSTRUCT, "void CallConstructor(void*)", WRAP_CON(CallConstuctor, void*), asCALL_GENERIC); assert(r >= 0);

Compiler error: type/value mismatch as argument 1 in template parameter list for ‘template<class T> struct gw::Constuctor’ … and later “expected a type, got 'CallConstuctor'. ClassType ”Motor" doesn't seem to make sense, but the WRAP_CON template indicates that a typename is what is expected.

How is this done with generic wrappers (I'm on arm64)?

Check out the code in add_on/scriptstdstring/scriptstdstring.cpp. It registers std::string using generic functions.

Advertisement

The WRAP_CON and WRAP_DES macros in the autowrapper add-on expect to receive the object type as the first parameter. The macro will generate the wrapper function for the constructor/destructor so you don't need to implement the function yourself.

r = mpEngine->RegisterObjectBehaviour("Motor", asBEHAVE_CONSTRUCT, "void f()", WRAP_CON(Motor, ()), asCALL_GENERIC); assert(r >= 0);

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

This topic is closed to new replies.

Advertisement