修复不兼容64位整数问题
This commit is contained in:
@@ -59,18 +59,18 @@ void module::globalfuncs::create_env(const std::string& lua_filepath,sol::this_s
|
|||||||
|
|
||||||
t.detach();
|
t.detach();
|
||||||
}
|
}
|
||||||
std::optional<int> module::globalfuncs::toint(const sol::object& obj)
|
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:
|
||||||
// 直接将数字转换为 int
|
// 直接将数字转换为 int
|
||||||
return obj.as<int>();
|
return obj.as<int64>();
|
||||||
case sol::type::string: {
|
case sol::type::string: {
|
||||||
// 尝试将字符串转换为 int
|
// 尝试将字符串转换为 int
|
||||||
std::string s = obj.as<std::string>();
|
std::string s = obj.as<std::string>();
|
||||||
try {
|
try {
|
||||||
return std::stoi(s);
|
return std::stoll(s);
|
||||||
}
|
}
|
||||||
catch (const std::exception&) {
|
catch (const std::exception&) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace module
|
|||||||
/// 转INT
|
/// 转INT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
static std::optional<int> toint(const sol::object& arg);
|
static std::optional<int64> toint(const sol::object& arg);
|
||||||
|
|
||||||
|
|
||||||
static void regist(sol::state* lua);
|
static void regist(sol::state* lua);
|
||||||
|
|||||||
Reference in New Issue
Block a user