mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 16:25:35 +00:00
catch invalid json to JsonDeserialize, use lua_nil instead of nil
This commit is contained in:
parent
96a0e4b6fb
commit
965935a0e6
@ -531,7 +531,10 @@ static void JsonDeserializeRecursive(sol::state_view& StateView, sol::table& tab
|
|||||||
sol::table TLuaEngine::StateThreadData::Lua_JsonDeserialize(const std::string& str) {
|
sol::table TLuaEngine::StateThreadData::Lua_JsonDeserialize(const std::string& str) {
|
||||||
sol::state_view StateView(mState);
|
sol::state_view StateView(mState);
|
||||||
auto table = StateView.create_table();
|
auto table = StateView.create_table();
|
||||||
// TODO: try / catch
|
if (!nlohmann::json::accept(str)) {
|
||||||
|
beammp_lua_error("string given to JsonDeserialize is not valid json.");
|
||||||
|
return sol::lua_nil;
|
||||||
|
}
|
||||||
nlohmann::json json = nlohmann::json::parse(str);
|
nlohmann::json json = nlohmann::json::parse(str);
|
||||||
if (json.is_object()) {
|
if (json.is_object()) {
|
||||||
for (const auto& entry : json.items()) {
|
for (const auto& entry : json.items()) {
|
||||||
@ -543,7 +546,7 @@ sol::table TLuaEngine::StateThreadData::Lua_JsonDeserialize(const std::string& s
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("JsonDeserialize expected array or object json, instead got " + std::string(json.type_name()));
|
beammp_lua_error("JsonDeserialize expected array or object json, instead got " + std::string(json.type_name()));
|
||||||
return sol::nil;
|
return sol::lua_nil;
|
||||||
}
|
}
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user