Comparsion operator:
bool operator ==(const asSFuncPtr& a, const asSFuncPtr& b)
{
for (size_t i = 0; i < sizeof(a.ptr.dummy); i++)
{
if (a.ptr.dummy[i] != b.ptr.dummy[i])
return false;
}
return a.flag == b.flag;
}
=========
struct Bas
{
void X() { }
};
struct Chi : public Bas
{
};
asMETHODPR(Bas, X, (), void) == asMETHODPR(Chi, X, (), void)
======
struct Bas
{
void X() { }
};
struct Bas2
{
};
struct Chi : public Bas, Bas2
{
};
asMETHODPR(Bas, X, (), void) != asMETHODPR(Chi, X, (), void)
=======
So usage asMETHODPR(BASE_CLASS, BASECLASSMETHOD, (), void) for registering methods of base class in separate functions cause crash in some situation [but asMETHODPR(DERIVED_CLASS, BASECLASSMETHOD, (), void) works]
https://github.com/1vanK/Urho3D/blob/master/Source/Urho3D/AngelScript/Generated_Members_Graphics.cpp
void CollectMembers_AnimatedModel(MemberCollection& members)
{
CollectMembers_StaticModel(members);
Remove(members.methods_, "ResourceRef StaticModel::GetModelAttr() const");
Remove(members.methods_, "bool Animatable::LoadJSON(const JSONValue& source) override");
Remove(members.methods_, "bool Animatable::LoadXML(const XMLElement& source) override");
members.methods_.Push(...);
MemberCollection store pointers asMETHODPR(…)
=======
You could probably also write it in such a way so that instead of passing a list of members you would just pass the name of the derived class, and thus do only a single if statement (and only for those bases classes whose members are hidden by any derived class).
If use templates:
template <class T> void RegisterUIElement(asIScriptEngine* engine, const char* className, bool isSprite = false)
{
// Base classes
RegisterAnimatable<T>(engine, className);
engine->RegisterObjectMethod(className, "void SetSize(int, int)", asMETHODPR(T, SetSize, (int, int), void), asCALL_THISCALL);
if (!isSprite)
engine->RegisterObjectMethod(className, "void SetPosition(int, int)", asMETHODPR(T, SetPosition, (int, int), void), asCALL_THISCALL);
}
just not compile because compiler considers asMETHODPR(T, SetPosition, (int, int), void)
but this function is hidden.
I can write
if (!isSprite)
engine->RegisterObjectMethod(className, "void SetPosition(int, int)", asMETHODPR(UIElement, SetPosition, (int, int), void), asCALL_THISCALL);
but then I am facing the problem described at the beginning of the post