Skip to content

Commit

Permalink
LuaEvent: Use traverse_get
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Oct 15, 2023
1 parent 72b49ab commit 9e8a69c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
1 change: 0 additions & 1 deletion 3rdParty/sol2/sol_config/sol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 4 additions & 14 deletions Source/utils/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sol::table>()) {
LogError("Events table missing!");
return;
}
const sol::object event = events.as<sol::table>()[name];
if (!event.is<sol::table>()) {
LogError("Events.{} event not registered", name);
return;
}
const sol::object trigger = event.as<sol::table>()["Trigger"];
if (!trigger.is<sol::function>()) {
const sol::state &lua = *luaState;
const auto trigger = lua.traverse_get<std::optional<sol::object>>("Events", name, "Trigger");
if (!trigger.has_value() || !trigger->is<sol::protected_function>()) {
LogError("Events.{}.Trigger is not a function", name);
return;
}
const sol::protected_function fn = trigger.as<sol::protected_function>();
const sol::protected_function fn = trigger->as<sol::protected_function>();
CheckResult(fn());
}

Expand Down

0 comments on commit 9e8a69c

Please sign in to comment.