diff --git a/src/module/globalfuns.cpp b/src/module/globalfuns.cpp index 6c2764d..d67eea5 100644 --- a/src/module/globalfuns.cpp +++ b/src/module/globalfuns.cpp @@ -64,12 +64,14 @@ std::optional module::globalfuncs::toint(const sol::object& obj) sol::type t = obj.get_type(); switch (t) { case sol::type::number: + { double value = obj.as(); // 检查小数部分是否为零 if (std::floor(value) == value) { return static_cast(value); } return std::nullopt; + } case sol::type::string: { // 尝试将字符串转换为 int std::string s = obj.as();