修复
This commit is contained in:
@@ -64,12 +64,14 @@ std::optional<int64> module::globalfuncs::toint(const sol::object& obj)
|
|||||||
sol::type t = obj.get_type();
|
sol::type t = obj.get_type();
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case sol::type::number:
|
case sol::type::number:
|
||||||
|
{
|
||||||
double value = obj.as<double>();
|
double value = obj.as<double>();
|
||||||
// 检查小数部分是否为零
|
// 检查小数部分是否为零
|
||||||
if (std::floor(value) == value) {
|
if (std::floor(value) == value) {
|
||||||
return static_cast<int64>(value);
|
return static_cast<int64>(value);
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
}
|
||||||
case sol::type::string: {
|
case sol::type::string: {
|
||||||
// 尝试将字符串转换为 int
|
// 尝试将字符串转换为 int
|
||||||
std::string s = obj.as<std::string>();
|
std::string s = obj.as<std::string>();
|
||||||
|
|||||||
Reference in New Issue
Block a user