summaryrefslogtreecommitdiff
path: root/src/config/lua/bindings/LuaBindingsRegistration.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2026-04-28 15:56:07 +0100
committerGitHub <noreply@github.com>2026-04-28 15:56:07 +0100
commit98fbbafef78057c818fb02b15c27e38ad2f5b5bc (patch)
treec62aa1eae704e7595d58f7edeb3804e8bfd0099d /src/config/lua/bindings/LuaBindingsRegistration.cpp
parentd4c6ff434c5c7aa66bc7c28e5ce336d2a694bfcc (diff)
config/errors: Report and categorize errors properly for actions (#14192)
Makes all errors categorized, some not displayed, some displayed. All errors can be obtained after hl.dispatch()
Diffstat (limited to 'src/config/lua/bindings/LuaBindingsRegistration.cpp')
-rw-r--r--src/config/lua/bindings/LuaBindingsRegistration.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/config/lua/bindings/LuaBindingsRegistration.cpp b/src/config/lua/bindings/LuaBindingsRegistration.cpp
index ba6804a9..0cb59364 100644
--- a/src/config/lua/bindings/LuaBindingsRegistration.cpp
+++ b/src/config/lua/bindings/LuaBindingsRegistration.cpp
@@ -26,6 +26,31 @@ static int hlPrint(lua_State* L) {
return 0;
}
+static SDispatchResult dispatchResultFromLua(lua_State* L, int idx) {
+ SDispatchResult result;
+
+ if (!lua_istable(L, idx))
+ return result;
+
+ lua_getfield(L, idx, "pass_event");
+ result.passEvent = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, idx, "ok");
+ if (lua_isboolean(L, -1))
+ result.success = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ if (!result.success) {
+ lua_getfield(L, idx, "error");
+ if (lua_isstring(L, -1))
+ result.error = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ }
+
+ return result;
+}
+
void Internal::registerBindingsImpl(lua_State* L, CConfigManager* mgr) {
Objects::CLuaTimer{}.setup(L);
Objects::CLuaEventSubscription{}.setup(L);
@@ -40,15 +65,21 @@ void Internal::registerBindingsImpl(lua_State* L, CConfigManager* mgr) {
int status = LUA_OK;
if (auto* mgr = CConfigManager::fromLuaState(L); mgr)
- status = mgr->guardedPCall(0, 0, 0, CConfigManager::LUA_TIMEOUT_KEYBIND_CALLBACK_MS, "keybind callback");
+ status = mgr->guardedPCall(0, 1, 0, CConfigManager::LUA_TIMEOUT_KEYBIND_CALLBACK_MS, "keybind callback");
else
- status = lua_pcall(L, 0, 0, 0);
+ status = lua_pcall(L, 0, 1, 0);
if (status != LUA_OK) {
- Config::Lua::mgr()->addError(std::format("error in keybind lambda: {}", lua_tostring(L, -1)));
+ Config::Lua::Bindings::Internal::reportError(L,
+ Config::Actions::SActionError{std::format("error in keybind lambda: {}", lua_tostring(L, -1)),
+ Config::Actions::eActionErrorLevel::ERROR, Config::Actions::eActionErrorCode::LUA_ERROR});
lua_pop(L, 1);
+ return {.success = false, .error = "lua keybind error"};
}
- return {};
+
+ auto result = dispatchResultFromLua(L, -1);
+ lua_pop(L, 1);
+ return result;
};
lua_newtable(L);