More using the getter macro, adds support for non const getter functions.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
2e8cf4379b
commit
29fe82f04d
|
@ -48,7 +48,6 @@ void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) {
|
|||
Ensure(r >= 0);
|
||||
}
|
||||
|
||||
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Battle, CreatureLib::Battling::ChoiceQueue, GetCurrentTurnQueue);
|
||||
CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battle* battle, u8 index) {
|
||||
return battle->GetSides()[index];
|
||||
}
|
||||
|
@ -98,24 +97,19 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) {
|
|||
}
|
||||
|
||||
void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
|
||||
int r = engine->RegisterObjectMethod("Battle", "const BattleLibrary@ get_Library() const property",
|
||||
asMETHOD(PkmnLib::Battling::Battle, GetLibrary), asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
|
||||
asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Battle", "bool get_CanFlee() const property",
|
||||
asMETHOD(PkmnLib::Battling::Battle, CanFlee), asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Battle", "uint get_CurrentTurn() const property",
|
||||
asMETHOD(PkmnLib::Battling::Battle, GetCurrentTurn), asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
REGISTER_GETTER("Battle", "const BattleLibrary@ get_Library() const property", CreatureLib::Battling::Battle,
|
||||
GetLibrary);
|
||||
REGISTER_GETTER("Battle", "bool get_CanFlee() const property", CreatureLib::Battling::Battle,
|
||||
CanFlee);
|
||||
REGISTER_GETTER("Battle", "uint get_CurrentTurn() const property", CreatureLib::Battling::Battle,
|
||||
GetCurrentTurn);
|
||||
REGISTER_GETTER("Battle", "BattleRandom@ get_Random() const property", CreatureLib::Battling::Battle,
|
||||
GetRandom);
|
||||
REGISTER_GETTER("Battle", "ChoiceQueue@ get_TurnQueue() const property", CreatureLib::Battling::Battle,
|
||||
GetCurrentTurnQueue);
|
||||
|
||||
r = engine->RegisterObjectMethod("Battle", "BattleRandom@ get_Random() const property",
|
||||
asMETHOD(PkmnLib::Battling::Battle, GetRandom), asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Battle", "ChoiceQueue@ get_TurnQueue() const property",
|
||||
asFUNCTION(GetCurrentTurnQueueWrapper), asCALL_CDECL_OBJFIRST);
|
||||
auto r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
|
||||
asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name)",
|
||||
asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
||||
|
|
|
@ -63,5 +63,36 @@ void RegisterGetter(asIScriptEngine* engine, const char* asType, const char* asD
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T, typename R, R (T::*Method)()>
|
||||
void RegisterGetter(asIScriptEngine* engine, const char* asType, const char* asDef) {
|
||||
if constexpr (std::is_enum<R>()) {
|
||||
auto l = [](T* p) { return (i32)(p->*Method)(); };
|
||||
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), i32), asCALL_CDECL_OBJFIRST) >= 0);
|
||||
} else if constexpr (is_specialization<R, ArbUt::BorrowedPtr>::value) {
|
||||
auto l = [](T* p) { return (void*)(p->*Method)().GetRaw(); };
|
||||
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0);
|
||||
} else if constexpr (is_specialization<R, std::unique_ptr>::value) {
|
||||
auto l = [](T* p) { return (void*)(p->*Method)().get(); };
|
||||
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0);
|
||||
} else if constexpr (is_specialization<R, ArbUt::OptionalBorrowedPtr>::value) {
|
||||
auto l = [](const T* p) {
|
||||
auto v = (p->*Method)();
|
||||
if (v.HasValue()) {
|
||||
return (void*)v.GetValue();
|
||||
}
|
||||
return (void*)nullptr;
|
||||
};
|
||||
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0);
|
||||
} else if constexpr (std::is_reference<R>::value) {
|
||||
static_assert(!std::is_enum<R>());
|
||||
auto l = [](T* p) { return (void*)&(p->*Method)(); };
|
||||
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0);
|
||||
} else {
|
||||
static_assert(!std::is_enum<R>());
|
||||
auto l = [](T* p) { return (p->*Method)(); };
|
||||
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), R), asCALL_CDECL_OBJFIRST) >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
#define REGISTER_GETTER(asType, asDef, cType, cFunc) \
|
||||
RegisterGetter<cType, std::result_of<decltype (&cType::cFunc)(cType)>::type, &cType::cFunc>(engine, asType, asDef);
|
||||
|
|
Loading…
Reference in New Issue