diff --git a/src/client/game/ui_scripting/script_value.cpp b/src/client/game/ui_scripting/script_value.cpp index bfabc0f9..85a70e6b 100644 --- a/src/client/game/ui_scripting/script_value.cpp +++ b/src/client/game/ui_scripting/script_value.cpp @@ -6,22 +6,22 @@ namespace ui_scripting { - hks_object::hks_object(const game::hks::HksObject& value) + hks_reference::hks_reference(const game::hks::HksObject& value) { this->assign(value); } - hks_object::hks_object(const hks_object& other) noexcept + hks_reference::hks_reference(const hks_reference& other) noexcept { this->operator=(other); } - hks_object::hks_object(hks_object&& other) noexcept + hks_reference::hks_reference(hks_reference&& other) noexcept { this->operator=(std::move(other)); } - hks_object& hks_object::operator=(const hks_object& other) noexcept + hks_reference& hks_reference::operator=(const hks_reference& other) noexcept { if (this != &other) { @@ -32,7 +32,7 @@ namespace ui_scripting return *this; } - hks_object& hks_object::operator=(hks_object&& other) noexcept + hks_reference& hks_reference::operator=(hks_reference&& other) noexcept { if (this != &other) { @@ -44,17 +44,17 @@ namespace ui_scripting return *this; } - hks_object::~hks_object() + hks_reference::~hks_reference() { this->release(); } - const game::hks::HksObject& hks_object::get() const + const game::hks::HksObject& hks_reference::get() const { return this->value_; } - void hks_object::assign(const game::hks::HksObject& value) + void hks_reference::assign(const game::hks::HksObject& value) { this->value_ = value; @@ -66,7 +66,7 @@ namespace ui_scripting state->m_apistack.top = top; } - void hks_object::release() + void hks_reference::release() { if (this->ref_) { @@ -222,7 +222,7 @@ namespace ui_scripting bool script_value::is() const { const auto number = this->get_raw().v.number; - return this->get_raw().t == game::hks::TNUMBER && static_cast(number) == number; + return this->get_type() == game::hks::TNUMBER && static_cast(number) == number; } template <> @@ -250,7 +250,7 @@ namespace ui_scripting template <> bool script_value::is() const { - return this->get_raw().t == game::hks::TUI64; + return this->get_type() == game::hks::TUI64; } template <> @@ -278,7 +278,7 @@ namespace ui_scripting template <> bool script_value::is() const { - return this->get_raw().t == game::hks::TBOOLEAN; + return this->get_type() == game::hks::TBOOLEAN; } template <> @@ -294,7 +294,7 @@ namespace ui_scripting template <> bool script_value::is() const { - return this->get_raw().t == game::hks::TNUMBER; + return this->get_type() == game::hks::TNUMBER; } template <> @@ -322,7 +322,7 @@ namespace ui_scripting template <> bool script_value::is() const { - return this->get_raw().t == game::hks::TSTRING; + return this->get_type() == game::hks::TSTRING; } template <> @@ -350,7 +350,7 @@ namespace ui_scripting template <> bool script_value::is() const { - return this->get_raw().t == game::hks::TLIGHTUSERDATA; + return this->get_type() == game::hks::TLIGHTUSERDATA; } template <> @@ -366,7 +366,7 @@ namespace ui_scripting template <> bool script_value::is() const { - return this->get_raw().t == game::hks::TUSERDATA; + return this->get_type() == game::hks::TUSERDATA; } template <> @@ -382,7 +382,7 @@ namespace ui_scripting template <> bool script_value::is() const { - return this->get_raw().t == game::hks::TTABLE; + return this->get_type() == game::hks::TTABLE; } template <> @@ -398,20 +398,25 @@ namespace ui_scripting template <> bool script_value::is() const { - return this->get_raw().t == game::hks::TIFUNCTION - || this->get_raw().t == game::hks::TCFUNCTION; + return this->get_type() == game::hks::TIFUNCTION + || this->get_type() == game::hks::TCFUNCTION; } template <> function script_value::get() const { - return {this->get_raw().v.cClosure, this->get_raw().t}; + return {this->get_raw().v.cClosure, this->get_type()}; } /*************************************************************** * **************************************************************/ + const game::hks::HksObjectType script_value::get_type() const + { + return this->value_.get().t; + } + const game::hks::HksObject& script_value::get_raw() const { return this->value_.get(); @@ -419,12 +424,12 @@ namespace ui_scripting bool script_value::operator==(const script_value& other) const { - if (this->get_raw().t != other.get_raw().t) + if (this->get_type() != other.get_type()) { return false; } - if (this->get_raw().t == game::hks::TSTRING) + if (this->get_type() == game::hks::TSTRING) { return this->get() == other.get(); } diff --git a/src/client/game/ui_scripting/script_value.hpp b/src/client/game/ui_scripting/script_value.hpp index d669ccfd..316c269d 100644 --- a/src/client/game/ui_scripting/script_value.hpp +++ b/src/client/game/ui_scripting/script_value.hpp @@ -62,18 +62,18 @@ namespace ui_scripting } } - class hks_object + class hks_reference { public: - hks_object() = default; - hks_object(const game::hks::HksObject& value); - hks_object(const hks_object& other) noexcept; - hks_object(hks_object&& other) noexcept; + hks_reference() = default; + hks_reference(const game::hks::HksObject& value); + hks_reference(const hks_reference& other) noexcept; + hks_reference(hks_reference&& other) noexcept; - hks_object& operator=(const hks_object& other) noexcept; - hks_object& operator=(hks_object&& other) noexcept; + hks_reference& operator=(const hks_reference& other) noexcept; + hks_reference& operator=(hks_reference&& other) noexcept; - ~hks_object(); + ~hks_reference(); const game::hks::HksObject& get() const; @@ -180,7 +180,7 @@ namespace ui_scripting { if (!this->is()) { - const auto hks_typename = game::hks::s_compilerTypeName[this->get_raw().t + 2]; + const auto hks_typename = game::hks::s_compilerTypeName[this->get_type() + 2]; const auto typename_ = get_typename(); throw std::runtime_error(utils::string::va("%s expected, got %s", @@ -196,9 +196,10 @@ namespace ui_scripting return this->as(); } + const game::hks::HksObjectType get_type() const; const game::hks::HksObject& get_raw() const; - hks_object value_{}; + hks_reference value_{}; private: template