Add angelscript implicit conversion from string to constString.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-07-04 16:13:26 +02:00
parent 7f1bc252ba
commit 665c47aa91
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 11 additions and 9 deletions

View File

@ -16,9 +16,7 @@ namespace PkmnLib::Library {
inline ArbUt::BorrowedPtr<const Item> Get(const ArbUt::BasicStringView& name) const {
return CreatureLib::Library::ItemLibrary::Get(name).ForceAs<const Item>();
}
inline ArbUt::BorrowedPtr<const Item> operator[](const ArbUt::BasicStringView& name) const {
return Get(name);
}
inline ArbUt::BorrowedPtr<const Item> operator[](const ArbUt::BasicStringView& name) const { return Get(name); }
void Insert(const ArbUt::StringView& name, const Item* item) {
CreatureLib::Library::ItemLibrary::Insert(name, item);

View File

@ -8,10 +8,9 @@ namespace PkmnLib::Library {
class MoveData : public CreatureLib::Library::AttackData {
private:
public:
MoveData(const ArbUt::StringView& name, uint8_t type, PkmnLib::Library::MoveCategory category,
uint8_t power, uint8_t accuracy, uint8_t baseUsage, CreatureLib::Library::AttackTarget target,
int8_t priority, const CreatureLib::Library::SecondaryEffect* effect,
std::unordered_set<uint32_t> flags);
MoveData(const ArbUt::StringView& name, uint8_t type, PkmnLib::Library::MoveCategory category, uint8_t power,
uint8_t accuracy, uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority,
const CreatureLib::Library::SecondaryEffect* effect, std::unordered_set<uint32_t> flags);
PkmnLib::Library::MoveCategory GetCategory() const;
};

View File

@ -12,8 +12,7 @@ namespace PkmnLib::Library {
return Get(name);
}
inline bool TryGet(const ArbUt::BasicStringView& name,
ArbUt::BorrowedPtr<const MoveData>& move) const {
inline bool TryGet(const ArbUt::BasicStringView& name, ArbUt::BorrowedPtr<const MoveData>& move) const {
auto v = move.As<const MoveData::AttackData>();
auto res = CreatureLib::Library::AttackLibrary::TryGet(name, v);
move = v.As<const MoveData>();

View File

@ -2,6 +2,9 @@
#include <Arbutils/StringView.hpp>
static void ConstructConstString(void* self) { new (self) ArbUt::StringView(); }
static void ConstructConstStringFromStd(void* self, const std::string& s) {
new (self) ArbUt::StringView(s.c_str(), s.length());
}
static void CopyConstructConstString(const ArbUt::StringView& other, void* self) {
new (self) ArbUt::StringView(other);
}
@ -18,6 +21,9 @@ void ConstStringRegister::Register(asIScriptEngine* engine) {
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 string &in s)",
asFUNCTION(ConstructConstStringFromStd), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f(const constString &in)",
asFUNCTION(CopyConstructConstString), asCALL_CDECL_OBJLAST);