From 9e8a69cc3533b65d65717db65ecd1d0ce5a537c9 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 15 Oct 2023 16:32:22 +0100 Subject: [PATCH] `LuaEvent`: Use `traverse_get` --- 3rdParty/sol2/sol_config/sol/config.hpp | 1 - Source/utils/lua.cpp | 18 ++++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/3rdParty/sol2/sol_config/sol/config.hpp b/3rdParty/sol2/sol_config/sol/config.hpp index 89feb676c74..8fdec629a4a 100644 --- a/3rdParty/sol2/sol_config/sol/config.hpp +++ b/3rdParty/sol2/sol_config/sol/config.hpp @@ -4,5 +4,4 @@ #define SOL_SAFE_REFERENCES 1 #define SOL_SAFE_FUNCTION_CALLS 1 #define SOL_SAFE_FUNCTION 1 -#define SOL_NO_NIL 0 #define SOL_IN_DEBUG_DETECTED 0 diff --git a/Source/utils/lua.cpp b/Source/utils/lua.cpp index 859dbb08a0d..66e6a8e9c95 100644 --- a/Source/utils/lua.cpp +++ b/Source/utils/lua.cpp @@ -129,23 +129,13 @@ void LuaShutdown() void LuaEvent(std::string_view name) { - sol::state &lua = *luaState; - const sol::object events = lua["Events"]; - if (!events.is()) { - LogError("Events table missing!"); - return; - } - const sol::object event = events.as()[name]; - if (!event.is()) { - LogError("Events.{} event not registered", name); - return; - } - const sol::object trigger = event.as()["Trigger"]; - if (!trigger.is()) { + const sol::state &lua = *luaState; + const auto trigger = lua.traverse_get>("Events", name, "Trigger"); + if (!trigger.has_value() || !trigger->is()) { LogError("Events.{}.Trigger is not a function", name); return; } - const sol::protected_function fn = trigger.as(); + const sol::protected_function fn = trigger->as(); CheckResult(fn()); }