• Create Account

### #ActualHeuristics

Posted 12 March 2013 - 06:57 AM

Thank you! I now understand that the way I was thinking about the existence of the constructors destructors etc in classes were wrong. I thought there was no change introduced to a struct when compiled simply because you added a default constructor (I thought the compiler did on its own if you didn't define one), that's why I thought it was fine to just use asOBJ_APP_CLASS_CDAK since then all of them would be called.

### #3Heuristics

Posted 12 March 2013 - 05:27 AM

Thank you! I now understand that the way I was thinking about the existence of the constructors destructors etc in classes were wrong. I thought there was no change introduced to a struct when compiled simply because you added a default constructor (I thought the compiler did on its own if you didn't define one), that's why I thought it was fine to just use asOBJ_APP_CLASS_CDAK since then all of them would be called.

It looks like the support for these type traits in the current mingw is a bit half-implemented so this is the best I could come up with:

#include <type_traits>
#include <tr1/type_traits>
template<typename T>
void automaticallyRegisterObjectTypeAsValue(asIScriptEngine *engine, std::string name) {
bool hasConstructor = !std::has_trivial_default_constructor<T>::value;
bool hasDestructor = !std::has_trivial_destructor<T>::value;
bool hasAssignmentOperator = !std::tr1::has_trivial_assign<T>::value;
bool hasCopyConstructor = !std::tr1::has_trivial_copy<T>::value;

asDWORD flags = asOBJ_VALUE | asOBJ_APP_CLASS;
if(hasConstructor)          flags = flags | asOBJ_APP_CLASS_CONSTRUCTOR;
if(hasDestructor)           flags = flags | asOBJ_APP_CLASS_DESTRUCTOR;
if(hasAssignmentOperator)   flags = flags | asOBJ_APP_CLASS_ASSIGNMENT;
if(hasCopyConstructor)      flags = flags | asOBJ_APP_CLASS_COPY_CONSTRUCTOR;

int r = engine->RegisterObjectType(name.c_str(), sizeof(T), flags ); assert( r >= 0 );
}


Edit::::

After testing a bit this solution does not appear to work. Currently not sure that gcc supports enough type traits to do this correctly.

### #2Heuristics

Posted 12 March 2013 - 03:22 AM

Thank you! I now understand that the way I was thinking about the existence of the constructors destructors etc in classes were wrong. I thought there was no change introduced to a struct when compiled simply because you added a default constructor (I thought the compiler did on its own if you didn't define one), that's why I thought it was fine to just use asOBJ_APP_CLASS_CDAK since then all of them would be called.

It looks like the support for these type traits in the current mingw is a bit half-implemented so this is the best I could come up with:

#include <type_traits>
#include <tr1/type_traits>
template<typename T>
void automaticallyRegisterObjectTypeAsValue(asIScriptEngine *engine, std::string name) {
bool hasConstructor = !std::has_trivial_default_constructor<T>::value;
bool hasDestructor = !std::has_trivial_destructor<T>::value;
bool hasAssignmentOperator = !std::tr1::has_trivial_assign<T>::value;
bool hasCopyConstructor = !std::tr1::has_trivial_copy<T>::value;

asDWORD flags = asOBJ_VALUE | asOBJ_APP_CLASS;
if(hasConstructor)          flags = flags | asOBJ_APP_CLASS_CONSTRUCTOR;
if(hasDestructor)           flags = flags | asOBJ_APP_CLASS_DESTRUCTOR;
if(hasAssignmentOperator)   flags = flags | asOBJ_APP_CLASS_ASSIGNMENT;
if(hasCopyConstructor)      flags = flags | asOBJ_APP_CLASS_COPY_CONSTRUCTOR;

int r = engine->RegisterObjectType(name.c_str(), sizeof(T), flags ); assert( r >= 0 );
}


### #1Heuristics

Posted 12 March 2013 - 03:22 AM

Thank you! I now understand that the way I was thinking about the existence of the constructors destructors etc in classes were wrong. I thought there was no change introduced to a struct when compiled simply because you added a default constructor (I thought the compiler did on its own if you didn't define one), that's why I thought it was fine to just use asOBJ_APP_CLASS_CDAK since then all of them would be called

It looks like the support for these type traits in the current mingw is a bit half-implemented so this is the best I could come up with:

#include <type_traits>
#include <tr1/type_traits>
template<typename T>
void automaticallyRegisterObjectTypeAsValue(asIScriptEngine *engine, std::string name) {
bool hasConstructor = !std::has_trivial_default_constructor<T>::value;
bool hasDestructor = !std::has_trivial_destructor<T>::value;
bool hasAssignmentOperator = !std::tr1::has_trivial_assign<T>::value;
bool hasCopyConstructor = !std::tr1::has_trivial_copy<T>::value;

asDWORD flags = asOBJ_VALUE | asOBJ_APP_CLASS;
if(hasConstructor)          flags = flags | asOBJ_APP_CLASS_CONSTRUCTOR;
if(hasDestructor)           flags = flags | asOBJ_APP_CLASS_DESTRUCTOR;
if(hasAssignmentOperator)   flags = flags | asOBJ_APP_CLASS_ASSIGNMENT;
if(hasCopyConstructor)      flags = flags | asOBJ_APP_CLASS_COPY_CONSTRUCTOR;

int r = engine->RegisterObjectType(name.c_str(), sizeof(T), flags ); assert( r >= 0 );
}

PARTNERS