Cleanup of C Interface, remove use of operator->, as it will throw when null.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-07-07 15:33:43 +02:00
parent c6974b6b5b
commit 2225d32432
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
16 changed files with 47 additions and 111 deletions

View File

@ -22,14 +22,14 @@ export bool CreatureLib_Battle_CanFlee(const Battle* p) { return p->CanFlee(); }
export uint8_t CreatureLib_Battle_CheckChoicesSetAndRun(Battle* p) { Try(p->CheckChoicesSetAndRun();) }
export ChoiceQueue* CreatureLib_Battle_GetCurrentTurnQueue(const Battle* p) {
return p->GetCurrentTurnQueue().operator->();
return p->GetCurrentTurnQueue().GetRaw();
}
export BattleRandom* CreatureLib_Battle_GetRandom(Battle* p) { return p->GetRandom(); }
export uint8_t CreatureLib_Battle_CreatureInField(bool& out, const Battle* p, Creature* c) {
Try(out = p->CreatureInField(c);)
}
export uint8_t CreatureLib_Battle_GetCreature(Creature*& out, const Battle* p, uint8_t side, uint8_t target) {
Try(out = p->GetCreature(side, target).operator->();)
Try(out = p->GetCreature(side, target).GetRaw();)
}
export uint8_t CreatureLib_Battle_ForceRecall(Battle* p, uint8_t side, uint8_t target) {

View File

@ -13,16 +13,8 @@ export uint8_t CreatureLib_BattleLibrary_Construct(const BattleLibrary*& out,
export void CreatureLib_BattleLibrary_Destruct(const BattleLibrary* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
#define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); }
SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetStaticLib, const CreatureLib::Library::DataLibrary*);
SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetStatCalculator, const BattleStatCalculator*);
SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetDamageLibrary, const DamageLibrary*);
SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetMiscLibrary, const MiscLibrary*);
SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetExperienceLibrary, const ExperienceLibrary*);
#undef SIMPLE_GET_FUNC
#undef SIMPLE_GET_FUNC_SMART_PTR
SMART_GET_FUNC(BattleLibrary, GetStaticLib, const CreatureLib::Library::DataLibrary*);
SMART_GET_FUNC(BattleLibrary, GetStatCalculator, const BattleStatCalculator*);
SMART_GET_FUNC(BattleLibrary, GetDamageLibrary, const DamageLibrary*);
SMART_GET_FUNC(BattleLibrary, GetMiscLibrary, const MiscLibrary*);
SMART_GET_FUNC(BattleLibrary, GetExperienceLibrary, const ExperienceLibrary*);

View File

@ -18,13 +18,8 @@ export uint8_t CreatureLib_Creature_Construct(Creature*& out, const BattleLibrar
export void CreatureLib_Creature_Destruct(const Creature* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
#define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); }
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetSpecies, const CreatureLib::Library::CreatureSpecies*);
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetVariant, const CreatureLib::Library::SpeciesVariant*);
BORROWED_GET_FUNC(Creature, GetSpecies, const CreatureLib::Library::CreatureSpecies*);
BORROWED_GET_FUNC(Creature, GetVariant, const CreatureLib::Library::SpeciesVariant*);
export uint8_t CreatureLib_Creature_ChangeVariant(Creature* p, const CreatureLib::Library::SpeciesVariant* variant) {
Try(p->ChangeVariant(variant);)
@ -39,7 +34,7 @@ export bool CreatureLib_Creature_HasHeldItem(const Creature* p, const char* name
return p->HasHeldItem(ArbUt::StringView(name));
}
export bool CreatureLib_Creature_HasHeldItemWithHash(const Creature* p, uint32_t hash) { return p->HasHeldItem(hash); }
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetHeldItem, const CreatureLib::Library::Item*);
BORROWED_GET_FUNC(Creature, GetHeldItem, const CreatureLib::Library::Item*);
export uint8_t CreatureLib_Creature_SetHeldItem(Creature* p, const char* name) {
Try(p->SetHeldItem(ArbUt::StringView(name));)
}
@ -48,8 +43,8 @@ export void CreatureLib_Creature_SetHeldItemFromItem(Creature* p, const Creature
return p->SetHeldItem(ArbUt::BorrowedPtr<const CreatureLib::Library::Item>(item));
}
SIMPLE_GET_FUNC(Creature, GetCurrentHealth, uint32_t);
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattle, Battle*);
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattleSide, BattleSide*);
BORROWED_GET_FUNC(Creature, GetBattle, Battle*);
BORROWED_GET_FUNC(Creature, GetBattleSide, BattleSide*);
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().data(); }
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
@ -87,8 +82,8 @@ export size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetA
export LearnedAttack* const* CreatureLib_Creature_GetAttack(Creature* p, size_t index) {
return p->GetAttacks().RawData();
}
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*);
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*);
BORROWED_GET_FUNC(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*);
BORROWED_GET_FUNC(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*);
export void CreatureLib_Creature_SetDisplaySpecies(Creature* p, const CreatureLib::Library::CreatureSpecies* species) {
return p->SetDisplaySpecies(ArbUt::BorrowedPtr<const CreatureLib::Library::CreatureSpecies>(species));
}
@ -109,7 +104,4 @@ export uint32_t CreatureLib_Creature_GetBaseStat(Creature* p, CreatureLib::Libra
}
export int8_t CreatureLib_Creature_GetStatBoost(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetStatBoost(stat);
}
#undef SIMPLE_GET_FUNC
#undef SIMPLE_GET_FUNC_SMART_PTR
}

View File

@ -10,7 +10,7 @@ export CreatureParty* CreatureLib_CreatureParty_ConstructFromArray(Creature* cre
export void CreatureLib_CreatureParty_Destruct(const CreatureParty* p) { delete p; }
export uint8_t CreatureLib_CreatureParty_GetAtIndex(Creature*& out, const CreatureParty* p, size_t index) {
Try(out = p->GetAtIndex(index).operator->();)
Try(out = p->GetAtIndex(index).GetRaw();)
}
export uint8_t CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { Try(p->Switch(a, b);) }

View File

@ -4,25 +4,17 @@ using namespace CreatureLib::Battling;
export void CreatureLib_EventData_Destruct(const EventData* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
#define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); }
SIMPLE_GET_FUNC(EventData, GetKind, EventDataKind);
SIMPLE_GET_FUNC_SMART_PTR(DamageEvent, GetCreature, Creature*);
BORROWED_GET_FUNC(DamageEvent, GetCreature, Creature*);
SIMPLE_GET_FUNC(DamageEvent, GetDamageSource, DamageSource);
SIMPLE_GET_FUNC(DamageEvent, GetOriginalHealth, uint32_t);
SIMPLE_GET_FUNC(DamageEvent, GetNewHealth, uint32_t);
SIMPLE_GET_FUNC_SMART_PTR(HealEvent, GetCreature, Creature*);
BORROWED_GET_FUNC(HealEvent, GetCreature, Creature*);
SIMPLE_GET_FUNC(HealEvent, GetOriginalHealth, uint32_t);
SIMPLE_GET_FUNC(HealEvent, GetNewHealth, uint32_t);
SIMPLE_GET_FUNC_SMART_PTR(FaintEvent, GetCreature, Creature*);
BORROWED_GET_FUNC(FaintEvent, GetCreature, Creature*);
export const char* CreatureLib_DisplayTextEvent_GetText(const DisplayTextEvent* p) { return p->GetText().c_str(); }
#undef SIMPLE_GET_FUNC
#undef SIMPLE_GET_FUNC_SMART_PTR

View File

@ -22,7 +22,7 @@ export bool CreatureLib_ExecutingAttack_IsCreatureTarget(ExecutingAttack* p, Cre
}
export Creature* CreatureLib_ExecutingAttack_GetUser(ExecutingAttack* p) { return p->GetUser().GetRaw(); }
export LearnedAttack* CreatureLib_ExecutingAttack_GetAttack(ExecutingAttack* p) { return p->GetAttack().operator->(); }
export LearnedAttack* CreatureLib_ExecutingAttack_GetAttack(ExecutingAttack* p) { return p->GetAttack().GetRaw(); }
#define HITDATA_GET_FUNC(name, returnType) \
export returnType CreatureLib_HitData##_##name(const ExecutingAttack::HitData* p) { return p->name(); }

View File

@ -9,13 +9,7 @@ export uint8_t CreatureLib_LearnedAttack_Construct(LearnedAttack*& out, const Cr
}
export void CreatureLib_LearnedAttack_Destruct(LearnedAttack* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
#define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); }
SIMPLE_GET_FUNC_SMART_PTR(LearnedAttack, GetAttack, const CreatureLib::Library::AttackData*);
BORROWED_GET_FUNC(LearnedAttack, GetAttack, const CreatureLib::Library::AttackData*);
SIMPLE_GET_FUNC(LearnedAttack, GetMaxUses, uint8_t);
SIMPLE_GET_FUNC(LearnedAttack, GetRemainingUses, uint8_t);
SIMPLE_GET_FUNC(LearnedAttack, GetLearnMethod, AttackLearnMethod);
@ -23,7 +17,4 @@ SIMPLE_GET_FUNC(LearnedAttack, GetLearnMethod, AttackLearnMethod);
export bool CreatureLib_LearnedAttack_TryUse(LearnedAttack* p, uint8_t uses) { return p->TryUse(uses); }
export void CreatureLib_LearnedAttack_DecreaseUses(LearnedAttack* p, uint8_t uses) { p->DecreaseUses(uses); }
export void CreatureLib_LearnedAttack_RestoreUses(LearnedAttack* p, uint8_t uses) { p->RestoreUses(uses); }
export void CreatureLib_LearnedAttack_RestoreAllUses(LearnedAttack* p) { p->RestoreAllUses(); }
#undef SIMPLE_GET_FUNC
#undef SIMPLE_GET_FUNC_SMART_PTR
export void CreatureLib_LearnedAttack_RestoreAllUses(LearnedAttack* p) { p->RestoreAllUses(); }

View File

@ -17,20 +17,15 @@ export SwitchTurnChoice* CreatureLib_SwitchTurnChoice_Construct(Creature* user,
export void CreatureLib_BaseTurnChoice_Destruct(const BaseTurnChoice* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
#define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); }
SIMPLE_GET_FUNC(BaseTurnChoice, GetKind, TurnChoiceKind)
SIMPLE_GET_FUNC_SMART_PTR(BaseTurnChoice, GetUser, Creature*)
BORROWED_GET_FUNC(BaseTurnChoice, GetUser, Creature*)
SIMPLE_GET_FUNC_SMART_PTR(AttackTurnChoice, GetAttack, LearnedAttack*)
BORROWED_GET_FUNC(AttackTurnChoice, GetAttack, LearnedAttack*)
SIMPLE_GET_FUNC(AttackTurnChoice, GetKind, TurnChoiceKind)
export uint8_t CreatureLib_BaseTurnChoice_GetPriority(int8_t& out, AttackTurnChoice* p) { Try(out = p->GetPriority()); }
SIMPLE_GET_FUNC_SMART_PTR(AttackTurnChoice, GetAttackScript, Script*)
SMART_GET_FUNC(AttackTurnChoice, GetAttackScript, Script*)
export uint8_t CreatureLib_BaseTurnChoice_GetTargetSideIndex(const AttackTurnChoice* p) {
return p->GetTarget().GetSideIndex();
}
@ -38,7 +33,4 @@ export uint8_t CreatureLib_BaseTurnChoice_GetTargetCreatureIndex(const AttackTur
return p->GetTarget().GetCreatureIndex();
}
SIMPLE_GET_FUNC_SMART_PTR(SwitchTurnChoice, GetNewCreature, Creature*)
#undef SIMPLE_GET_FUNC
#undef SIMPLE_GET_FUNC_SMART_PTR
BORROWED_GET_FUNC(SwitchTurnChoice, GetNewCreature, Creature*)

View File

@ -25,4 +25,11 @@ public:
return CreatureLibException; \
}
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
#define BORROWED_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().GetRaw(); }
#define SMART_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().get(); }
#endif // CREATURELIB_CORE_HPP

View File

@ -27,9 +27,6 @@ export uint8_t CreatureLib_AttackData_Construct(AttackData*& out, const char* na
export void CreatureLib_AttackData_Destruct(const AttackData* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
export const char* CreatureLib_AttackData_GetName(const AttackData* p) { return p->GetName().c_str(); }
SIMPLE_GET_FUNC(AttackData, GetType, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetCategory, AttackCategory);
@ -51,6 +48,4 @@ export const char* CreatureLib_AttackData_GetSecondaryEffectName(const AttackDat
export bool CreatureLib_AttackData_HasFlag(const AttackData* p, const char* key) {
return p->HasFlag(ArbUt::StringView::CalculateHash(key));
}
#undef SIMPLE_GET_FUNC
}

View File

@ -18,23 +18,23 @@
export bool simpleName##_TryGet(fullname* p, const char* name, const returnType*& out) { \
ArbUt::BorrowedPtr<const returnType> o; \
auto v = p->TryGet(ArbUt::StringView::CalculateHash(name), o); \
out = o.operator->(); \
out = o.GetRaw(); \
return v; \
} \
\
export bool simpleName##_TryGetWithHash(fullname* p, uint32_t hashedKey, const returnType*& out) { \
ArbUt::BorrowedPtr<const returnType> o; \
auto v = p->TryGet(hashedKey, o); \
out = o.operator->(); \
out = o.GetRaw(); \
return v; \
} \
\
export uint8_t simpleName##_Get(fullname* p, const char* name, const returnType*& out) { \
Try(out = p->Get(ArbUt::StringView::CalculateHash(name)).operator->();) \
Try(out = p->Get(ArbUt::StringView::CalculateHash(name)).GetRaw();) \
} \
\
export uint8_t simpleName##_GetWithHash(fullname* p, uint32_t hashedKey, const returnType*& out) { \
Try(out = p->Get(hashedKey).operator->();) \
Try(out = p->Get(hashedKey).GetRaw();) \
} \
\
export size_t simpleName##_GetCount(fullname* p) { return p->GetCount(); }

View File

@ -12,9 +12,6 @@ export uint8_t CreatureLib_CreatureSpecies_Construct(CreatureSpecies*& out, uint
export void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
SIMPLE_GET_FUNC(CreatureSpecies, GetId, uint16_t);
SIMPLE_GET_FUNC(CreatureSpecies, GetGenderRate, float);
SIMPLE_GET_FUNC(CreatureSpecies, GetCaptureRate, uint8_t);
@ -54,5 +51,3 @@ export uint8_t CreatureLib_CreatureSpecies_GetVariantWithHash(const SpeciesVaria
export uint8_t CreatureLib_CreatureSpecies_SetVariant(CreatureSpecies* p, const char* name, SpeciesVariant* variant) {
Try(p->SetVariant(ArbUt::StringView(name), variant);)
}
#undef SIMPLE_GET_FUNC

View File

@ -10,14 +10,9 @@ export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, Librar
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); }
SIMPLE_GET_FUNC(DataLibrary, GetSettings, const LibrarySettings*);
SIMPLE_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetAttackLibrary, const AttackLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetItemLibrary, const ItemLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetGrowthRates, const GrowthRateLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetTypeLibrary, const TypeLibrary*);
#undef SIMPLE_GET_FUNC
SMART_GET_FUNC(DataLibrary, GetSettings, const LibrarySettings*);
SMART_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*);
SMART_GET_FUNC(DataLibrary, GetAttackLibrary, const AttackLibrary*);
SMART_GET_FUNC(DataLibrary, GetItemLibrary, const ItemLibrary*);
SMART_GET_FUNC(DataLibrary, GetGrowthRates, const GrowthRateLibrary*);
SMART_GET_FUNC(DataLibrary, GetTypeLibrary, const TypeLibrary*);

View File

@ -14,9 +14,6 @@ export Item* CreatureLib_Item_Construct(const char* name, ItemCategory category,
export void CreatureLib_Item_Destruct(const Item* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
export const char* CreatureLib_Item_GetName(const Item* p) { return p->GetName().c_str(); }
SIMPLE_GET_FUNC(Item, GetCategory, ItemCategory);
SIMPLE_GET_FUNC(Item, GetBattleCategory, BattleItemCategory);
@ -24,6 +21,4 @@ SIMPLE_GET_FUNC(Item, GetPrice, int32_t);
export bool CreatureLib_Item_HasFlag(const Item* p, const char* key) {
return p->HasFlag(ArbUt::StringView::CalculateHash(key));
}
#undef SIMPLE_GET_FUNC
}

View File

@ -8,10 +8,5 @@ export const LibrarySettings* CreatureLib_LibrarySettings_Construct(uint8_t maxi
export void CreatureLib_LibrarySettings_Destruct(const LibrarySettings* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const CreatureLib::Library::type* p) { return p->name(); }
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalLevel, uint8_t);
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalMoves, uint8_t);
#undef SIMPLE_GET_FUNC
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalMoves, uint8_t);

View File

@ -27,9 +27,6 @@ export SpeciesVariant* CreatureLib_SpeciesVariant_Construct(
export void CreatureLib_SpeciesVariant_Destruct(SpeciesVariant* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const CreatureLib::Library::type* p) { return p->name(); }
export const char* CreatureLib_SpeciesVariant_GetName(SpeciesVariant* p) { return p->GetName().c_str(); }
SIMPLE_GET_FUNC(SpeciesVariant, GetHeight, float);
SIMPLE_GET_FUNC(SpeciesVariant, GetWeight, float);
@ -45,7 +42,5 @@ export uint8_t CreatureLib_SpeciesVariant_GetTalent(SpeciesVariant* p, bool secr
Try(out = p->GetTalent(TalentIndex(secret, index)).c_str();)
}
export const LearnableAttacks* CreatureLib_SpeciesVariant_GetLearnableAttacks(SpeciesVariant* p) {
return p->GetLearnableAttacks().operator->();
return p->GetLearnableAttacks().GetRaw();
}
#undef SIMPLE_GET_FUNC