PkmnLib/src/ScriptResolving/AngelScript/TypeRegistry/ConstString.cpp

62 lines
3.2 KiB
C++
Raw Normal View History

#include "ConstString.hpp"
#include <Arbutils/Ensure.hpp>
2022-03-23 18:16:27 +00:00
#include <Arbutils/StringView.hpp>
2022-03-23 18:16:27 +00:00
static ArbUt::StringView* ConstructConstString() { return new ArbUt::StringView(); }
static ArbUt::StringView* ConstructConstStringFromStd(const std::string& s) {
return new ArbUt::StringView(s.c_str(), s.length());
}
2022-03-23 18:16:27 +00:00
static ArbUt::StringView* CopyConstructConstString(ArbUt::StringView* other) {
return new ArbUt::StringView(*other);
2020-07-04 13:50:30 +00:00
}
2022-03-23 18:16:27 +00:00
static void DestructConstString(ArbUt::StringView* self) { delete self; }
2020-07-04 13:50:30 +00:00
static bool ConstStringEquality(const ArbUt::StringView& a, const ArbUt::StringView& b) { return a == b; }
static bool ConstStringStdStringEquality(const ArbUt::StringView& a, const std::string& b) { return a == b; }
static uint32_t ImplConstStringHashConv(const ArbUt::StringView& s) { return s.GetHash(); }
static std::string ImplConstStringStringConv(const ArbUt::StringView& s) { return std::string(s.std_str()); }
void ConstStringRegister::Register(asIScriptEngine* engine) {
2022-03-23 18:16:27 +00:00
auto r = engine->RegisterObjectType("constString", sizeof(ArbUt::StringView), asOBJ_SCOPED | asOBJ_REF);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
2020-04-07 10:04:23 +00:00
2022-03-23 18:16:27 +00:00
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_FACTORY, "constString@ f()",
asFUNCTION(ConstructConstString), asCALL_CDECL);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
2022-03-23 18:16:27 +00:00
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_FACTORY, "constString@ f(const string &in s)",
asFUNCTION(ConstructConstStringFromStd), asCALL_CDECL);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
2020-04-07 10:04:23 +00:00
2022-03-23 18:16:27 +00:00
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_FACTORY, "constString@ f(const constString &in)",
asFUNCTION(CopyConstructConstString), asCALL_CDECL);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
2020-04-07 10:04:23 +00:00
2022-03-23 18:16:27 +00:00
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_RELEASE, "void f()", asFUNCTION(DestructConstString),
asCALL_CDECL_OBJFIRST);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
2020-04-07 10:04:23 +00:00
2020-07-04 13:50:30 +00:00
r = engine->RegisterObjectMethod(
"constString", "constString &opAssign(const constString &in)",
asMETHODPR(ArbUt::StringView, operator=, (const ArbUt::StringView&), ArbUt::StringView&), asCALL_THISCALL);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
2020-04-07 10:04:23 +00:00
2020-07-04 13:50:30 +00:00
r = engine->RegisterObjectMethod(
"constString", "bool opEquals(const constString &in) const",
asFUNCTIONPR(ConstStringEquality, (const ArbUt::StringView&, const ArbUt::StringView&), bool),
asCALL_CDECL_OBJFIRST);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
2020-04-07 10:04:23 +00:00
r = engine->RegisterObjectMethod(
"constString", "bool opEquals(const string &in) const",
2020-07-04 13:50:30 +00:00
asFUNCTIONPR(ConstStringStdStringEquality, (const ArbUt::StringView&, const std::string&), bool),
2020-04-07 10:04:23 +00:00
asCALL_CDECL_OBJFIRST);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
2020-04-07 10:04:23 +00:00
r = engine->RegisterObjectMethod("constString", "uint opImplConv()",
2020-07-04 13:50:30 +00:00
asFUNCTIONPR(ImplConstStringHashConv, (const ArbUt::StringView&), uint32_t),
2020-04-07 10:04:23 +00:00
asCALL_CDECL_OBJFIRST);
2020-12-13 11:32:52 +00:00
Ensure(r >= 0);
r = engine->RegisterObjectMethod("constString", "string opImplConv()",
asFUNCTIONPR(ImplConstStringStringConv, (const ArbUt::StringView&), std::string),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
}