From 2cdfc0ce29a4c094f9e0cd9a8d7d1983e72aa4c5 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 16 Dec 2019 10:26:22 +0800 Subject: [PATCH] CObjectNumber for Lua interop needs to deal with both double and sint64 types, cannot have separate CObjectInteger type --- code/ryzom/common/src/game_share/object.cpp | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/code/ryzom/common/src/game_share/object.cpp b/code/ryzom/common/src/game_share/object.cpp index c8e238107..4b12cf3ea 100644 --- a/code/ryzom/common/src/game_share/object.cpp +++ b/code/ryzom/common/src/game_share/object.cpp @@ -801,9 +801,9 @@ void CObjectNumber::doSerialize(std::string& out, CSerializeContext& /* context { //H_AUTO(R2_CObjectNumber_doSerialize) nlassert(!getGhost()); - if (m_IsInteger) + if (doIsInteger()) { - out += NLMISC::toString(m_Value.Integer); + out += NLMISC::toString(getIntegerValue()); } else { @@ -852,15 +852,20 @@ bool CObjectNumber::set(const std::string& key, const std::string & value) BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false); double num; sint64 i; + if (NLMISC::fromString(value, i)) + { + if (NLMISC::toString(i) == value) + { + m_IsInteger = true; + m_Value.Integer = i; + return true; + } + } if (NLMISC::fromString(value, num)) { m_IsInteger = false; m_Value.Number = num; - } - if (NLMISC::fromString(value, i)) - { - m_IsInteger = true; - m_Value.Number = i; + return true; } return false; } @@ -905,9 +910,8 @@ bool CObjectNumber::setObject(const std::string& /* key */, CObject* value) bool CObjectNumber::equal(const CObject* other) const { if (!other) return false; - if (isInteger()) + if (isInteger() && other->isInteger()) { - if (!other->isInteger()) return false; return (getIntegerValue() == other->toInteger()); }