mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-12 17:54:04 +00:00
fix success/error handling in lua engine
This commit is contained in:
+15
-3
@@ -510,7 +510,11 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerGlobalEvent(const std::string
|
||||
auto LuaResult = Fn(LocalArgs);
|
||||
auto Result = std::make_shared<TLuaResult>(mStateId, Handler);
|
||||
if (LuaResult.valid()) {
|
||||
Result->MarkReadySuccess(LuaResult);
|
||||
try {
|
||||
Result->MarkReadySuccess(LuaResult);
|
||||
} catch (const std::exception& e) {
|
||||
Result->MarkReadyError(fmt::format("Call was successful, but result could not be serialized"));
|
||||
}
|
||||
} else {
|
||||
Result->MarkReadyError("Function result in TriggerGlobalEvent was invalid");
|
||||
}
|
||||
@@ -1194,7 +1198,11 @@ void TLuaEngine::StateThreadData::operator()() {
|
||||
sol::state_view StateView(mState);
|
||||
auto Res = StateView.safe_script(*S.first.Content, sol::script_pass_on_error, S.first.FileName);
|
||||
if (Res.valid()) {
|
||||
S.second->MarkReadySuccess(std::move(Res));
|
||||
try {
|
||||
S.second->MarkReadySuccess(std::move(Res));
|
||||
} catch (const std::exception& e) {
|
||||
S.second->MarkReadyError(fmt::format("Call was successful, but result could not be serialized"));
|
||||
}
|
||||
} else {
|
||||
S.second->MarkReadyError(std::move(Res));
|
||||
}
|
||||
@@ -1254,7 +1262,11 @@ void TLuaEngine::StateThreadData::operator()() {
|
||||
}
|
||||
auto Res = Fn(sol::as_args(LuaArgs));
|
||||
if (Res.valid()) {
|
||||
Result->MarkReadySuccess(std::move(Res));
|
||||
try {
|
||||
Result->MarkReadySuccess(std::move(Res));
|
||||
} catch (const std::exception& e) {
|
||||
Result->MarkReadyError(fmt::format("Call was successful, but result could not be serialized"));
|
||||
}
|
||||
} else {
|
||||
Result->MarkReadyError(std::move(Res));
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ void TLuaResult::MarkReadySuccess(sol::object Res) {
|
||||
|
||||
void TLuaResult::MarkReadyError(sol::protected_function_result Res) {
|
||||
std::unique_lock Lock(mMutex);
|
||||
mError = true;
|
||||
SetErrorMessageFromResult(Res);
|
||||
|
||||
MarkAsReady();
|
||||
|
||||
Reference in New Issue
Block a user