Angelscript support for ConstString.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-07 12:04:23 +02:00
parent 1046eceacf
commit aa8915b314
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
12 changed files with 68 additions and 23 deletions

View File

@ -61,11 +61,11 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
asMETHOD(CreatureLib::Battling::Battle, GetCurrentTurnQueue), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void AddVolatile(const string &in name) const",
"Battle", "void AddVolatile(const constString &in name) const",
asMETHODPR(CreatureLib::Battling::Battle, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void RemoveVolatile(const string &in name) const",
"Battle", "void RemoveVolatile(const constString &in name) const",
asMETHODPR(CreatureLib::Battling::Battle, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
assert(r >= 0);
}

View File

@ -114,7 +114,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const string &in name) const",
r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const",
asFUNCTION(HasHeldItem), asCALL_CDECL_OBJLAST);
assert(r >= 0);
r = engine->RegisterObjectMethod(
@ -133,7 +133,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Pokemon", "const string& get_Nickname() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetNickname), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const string& get_ActiveAbility() const property",
r = engine->RegisterObjectMethod("Pokemon", "const constString& get_ActiveAbility() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetActiveTalent), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property",
@ -182,11 +182,11 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asMETHOD(PkmnLib::Battling::Pokemon, GetStatBoost), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod(
"Pokemon", "void AddVolatile(const string &in name) const",
"Pokemon", "void AddVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod(
"Pokemon", "void RemoveVolatile(const string &in name) const",
"Pokemon", "void RemoveVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
assert(r >= 0);
}

View File

@ -1,14 +1,59 @@
#include "ConstString.hpp"
using ConstString = Arbutils::CaseInsensitiveConstString;
static void ConstructConstString(ConstString* self) { self = new ConstString(); }
static void CopyConstructConstString(const ConstString& other, ConstString* self) { self = new ConstString(other); }
static void DestructConstString(ConstString* self) { self->~ConstString(); }
static bool ConstStringEquality(const ConstString& a, const ConstString& b) { return a == b; }
static bool ConstStringStdStringEquality(const ConstString& a, const std::string& b) { return a == b; }
static ConstString ImplStdStringConstStringConv(const std::string& s) { return ConstString(s); }
static std::string ImplConstStringStdStringConv(const ConstString& s) { return s.std_str(); }
static uint32_t ImplConstStringHashConv(const ConstString& s) { return s.GetHash(); }
void ConstStringRegister::Register(asIScriptEngine* engine) {
auto r = engine->RegisterObjectType("constString", sizeof(Arbutils::CaseInsensitiveConstString),
asOBJ_VALUE | asOBJ_POD);
asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<ConstString>());
Assert(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructConstString),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f(const constString &in)",
asFUNCTION(CopyConstructConstString), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructConstString),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("string", "constString &opAssign(const constString &in)",
asMETHODPR(ConstString, operator=,(const ConstString&), ConstString&),
asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("constString", "bool opEquals(const constString &in) const",
asFUNCTIONPR(ConstStringEquality, (const ConstString&, const ConstString&), bool),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"constString", "bool opEquals(const string &in) const",
asFUNCTIONPR(ConstStringStdStringEquality, (const ConstString&, const std::string&), bool),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("string", "constString opImplConv()",
asFUNCTIONPR(ImplStdStringConstStringConv, (const std::string&), ConstString),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("constString", "string opImplConv()",
asFUNCTIONPR(ImplConstStringStdStringConv, (const ConstString&), std::string),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("constString", "uint opImplConv()",
asFUNCTIONPR(ImplConstStringHashConv, (const ConstString&), uint32_t),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
}

View File

@ -31,11 +31,11 @@ void RegisterGrowthRateTypes::RegisterGrowthRateLibrary(asIScriptEngine* engine)
[[maybe_unused]] int r = engine->RegisterObjectType("GrowthRateLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("GrowthRateLibrary",
"uint8 CalculateLevel(const string &in growthRate, uint experience) const",
"uint8 CalculateLevel(const constString &in growthRate, uint experience) const",
asFUNCTION(CalculateLevel), asCALL_CDECL_OBJLAST);
assert(r >= 0);
r = engine->RegisterObjectMethod("GrowthRateLibrary",
"uint CalculateExperience(const string &in growthRate, uint8 experience) const",
"uint CalculateExperience(const constString &in growthRate, uint8 experience) const",
asFUNCTION(CalculateExperience), asCALL_CDECL_OBJLAST);
assert(r >= 0);
}

View File

@ -61,7 +61,7 @@ static bool HasFlag(const PkmnLib::Library::Item* obj, const Arbutils::CaseInsen
void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("Item", "const string& get_Name() const property",
r = engine->RegisterObjectMethod("Item", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::Item, GetName), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Item", "ItemCategory get_Category() const property",
@ -73,7 +73,7 @@ void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Item", "int get_Price() const property",
asMETHOD(PkmnLib::Library::Item, GetPrice), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Item", "bool HasFlag(const string &in flag) const",
r = engine->RegisterObjectMethod("Item", "bool HasFlag(const constString &in flag) const",
asFUNCTION(HasFlag), asCALL_CDECL_OBJLAST);
assert(r >= 0);
@ -82,7 +82,7 @@ void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
void RegisterItemTypes::RegisterItemLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("ItemLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("ItemLibrary", "const Item@ Get(const string &in name) const",
r = engine->RegisterObjectMethod("ItemLibrary", "const Item@ Get(const constString &in name) const",
asMETHOD(PkmnLib::Library::ItemLibrary, Get), asCALL_THISCALL);
assert(r >= 0);
}

View File

@ -53,7 +53,7 @@ static bool HasFlag(const PkmnLib::Library::MoveData* obj, const Arbutils::CaseI
void RegisterMoveTypes::RegisterMoveType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveData", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "const string& get_Name() const property",
r = engine->RegisterObjectMethod("MoveData", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::MoveData, GetName), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Type() const property",
@ -77,14 +77,14 @@ void RegisterMoveTypes::RegisterMoveType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property",
asMETHOD(PkmnLib::Library::MoveData, GetPriority), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const string &in flag) const",
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const constString &in flag) const",
asFUNCTION(HasFlag), asCALL_CDECL_OBJLAST);
assert(r >= 0);
}
void RegisterMoveTypes::RegisterMoveLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("MoveLibrary", "const MoveData@ Get(const string &in name) const",
r = engine->RegisterObjectMethod("MoveLibrary", "const MoveData@ Get(const constString &in name) const",
asMETHOD(PkmnLib::Library::MoveLibrary, Get), asCALL_THISCALL);
assert(r >= 0);
}

View File

@ -48,7 +48,7 @@ static const PkmnLib::Library::PokemonForme* GetFormeWrapper(const std::string&
void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("Species", "const string& get_Name() const property",
r = engine->RegisterObjectMethod("Species", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetName), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Species", "uint16 get_Id() const property",
@ -78,7 +78,7 @@ const ConstString& GetAbility(PkmnLib::Library::PokemonForme* p, bool hidden, ui
void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Forme", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("Forme", "const string& get_Name() const property",
r = engine->RegisterObjectMethod("Forme", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::PokemonForme, GetName), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Forme", "float get_Weight() const property",
@ -108,7 +108,7 @@ void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
void RegisterSpeciesTypes::RegisterSpeciesLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("SpeciesLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("SpeciesLibrary", "const Species@ Get(const string &in name) const",
r = engine->RegisterObjectMethod("SpeciesLibrary", "const Species@ Get(const constString &in name) const",
asMETHOD(PkmnLib::Library::SpeciesLibrary, Get), asCALL_THISCALL);
assert(r >= 0);
}

View File

@ -13,7 +13,7 @@ static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const Arbuti
void RegisterTypeLibrary::RegisterTypeLibraryType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("TypeLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("TypeLibrary", "uint8 GetTypeId(const string &in name) const",
r = engine->RegisterObjectMethod("TypeLibrary", "uint8 GetTypeId(const constString &in name) const",
asFUNCTION(GetTypeId), asCALL_CDECL_OBJLAST);
assert(r >= 0);
r = engine->RegisterObjectMethod("TypeLibrary", "float GetSingleEffectiveness(uint8 attacking, uint8 defensive) const",

View File

@ -17,7 +17,7 @@ class testScript1 {
bool testHeldItem(Pokemon@ p, Item@ item){ return p.HeldItem is item; }
bool testCurrentHealth(Pokemon@ p, uint health){ return p.CurrentHealth == health; }
bool testNickname(Pokemon@ p, const string& name){ return p.Nickname == name; }
bool testActiveAbility(Pokemon@ p, const string &in ability){ return p.ActiveAbility == ability; }
bool testActiveAbility(Pokemon@ p, const constString &in ability){ return p.ActiveAbility == ability; }
bool testIsFainted(Pokemon@ p, bool b){ return p.IsFainted == b; }
bool testType(Pokemon@ p, uint index, uint8 type){ return p.GetTypes()[index] == type; }
bool testHasType(Pokemon@ p, uint8 type){ return p.HasType(type); }

View File

@ -166,7 +166,7 @@ TEST_CASE("Validate Forme GetAbility in Script") {
auto ability = forme->GetAbility(CreatureLib::Library::TalentIndex(false, 0));
data.Context->SetArgAddress(1, &ability);
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
// REQUIRE((bool)data.Context->GetReturnWord());
REQUIRE((bool)data.Context->GetReturnWord());
}
#endif

View File

@ -7,7 +7,7 @@ static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
class testScript1 {
bool testName(const Item@ i, const string &in name){ return i.Name == name; }
bool testName(const Item@ i, const constString &in name){ return i.Name == name; }
bool testCategory(const Item@ i, ItemCategory category){ return i.Category == category; }
bool testBattleCategory(const Item@ i, BattleItemCategory category){ return i.BattleCategory == category; }
bool testPrice(const Item@ i, int price){ return i.Price == price; }

View File

@ -7,7 +7,7 @@ static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"(
namespace Pokemon{
class testScript1 {
bool testName(const MoveData@ s, const string &in name){ return s.Name == name; }
bool testName(const MoveData@ s, const constString &in name){ return s.Name == name; }
bool testType(const MoveData@ s, uint8 type){ return s.Type == type; }
bool testCategory(const MoveData@ s, MoveCategory category){ return s.Category == category; }
bool testBasePower(const MoveData@ s, uint8 basePower){ return s.BasePower == basePower; }