From 18805362763168ac81af052aee64319c33f172f9 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 17 Sep 2021 02:26:49 +0200 Subject: [PATCH] Lua: Call onInit properly --- src/TLuaEngine.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index 5a45b15..e4c2d47 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -40,11 +40,11 @@ void TLuaEngine::operator()() { // lua engine main thread CollectAndInitPlugins(); // now call all onInit's - for (const auto& Pair : mLuaStates) { - auto Res = EnqueueFunctionCall(Pair.first, "onInit", {}); - Res->WaitUntilReady(); // FIXME this dumb, dont do this, this is smelly! - if (Res->Error && Res->ErrorMessage != TLuaEngine::BeamMPFnNotFoundError) { - beammp_lua_error("Calling \"onInit\" on \"" + Pair.first + "\" failed: " + Res->ErrorMessage); + auto Futures = TriggerEvent("onInit"); + WaitForAll(Futures); + for (const auto& Future : Futures) { + if (Future->Error) { + beammp_lua_error("Calling \"onInit\" on \"" + Future->StateId + "\" failed: " + Future->ErrorMessage); } } // this thread handles timers