From f21d3d038921f401ecb703ec89fef9129bdaf40b Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Wed, 20 Jul 2022 14:56:58 +0200 Subject: [PATCH] fix bug which caused Lua hot-reload not to report syntax errors --- Changelog.md | 1 + src/TPluginMonitor.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index aa104b3..5b87d71 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ - FIXED a fatal exception on LuaEngine startup if Resources/Server is a symlink - FIXED onInit not being called on hot-reload - FIXED incorrect timing calculation of Lua EventTimer loop +- FIXED bug which caused hot-reload not to report syntax errors # v3.0.2 diff --git a/src/TPluginMonitor.cpp b/src/TPluginMonitor.cpp index df575f1..3332ae1 100644 --- a/src/TPluginMonitor.cpp +++ b/src/TPluginMonitor.cpp @@ -48,9 +48,13 @@ void TPluginMonitor::operator()() { TLuaChunk Chunk(Contents, Pair.first, fs::path(Pair.first).parent_path().string()); auto StateID = mEngine->GetStateIDForPlugin(fs::path(Pair.first).parent_path()); auto Res = mEngine->EnqueueScript(StateID, Chunk); - mEngine->AddResultToCheck(Res); - mEngine->ReportErrors(mEngine->TriggerLocalEvent(StateID, "onInit")); - mEngine->ReportErrors(mEngine->TriggerEvent("onFileChanged", "", Pair.first)); + Res->WaitUntilReady(); + if (Res->Error) { + beammp_lua_errorf("Error while hot-reloading \"{}\": {}", Pair.first, Res->ErrorMessage); + } else { + mEngine->ReportErrors(mEngine->TriggerLocalEvent(StateID, "onInit")); + mEngine->ReportErrors(mEngine->TriggerEvent("onFileChanged", "", Pair.first)); + } } else { // is in subfolder, dont reload, just trigger an event beammp_debugf("File \"{}\" changed, not reloading because it's in a subdirectory. Triggering 'onFileChanged' event instead", Pair.first);