summaryrefslogtreecommitdiff
path: root/src/config/lua/bindings/LuaBindingsRegistration.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2026-04-26 15:16:36 +0100
committerGitHub <noreply@github.com>2026-04-26 15:16:36 +0100
commit5ba33f846129f3e6c0505b19f94634b24505e828 (patch)
treeaaacabe678006040c342935481a86607c66607fd /src/config/lua/bindings/LuaBindingsRegistration.cpp
parent329b2b356dd92ac07f4e2aa69cbce82ee9ba9d19 (diff)
config/lua: init lua config manager, use lua if available (#13817)
Adds a new lua config manager, which will automatically be used if there is a lua config present.
Diffstat (limited to 'src/config/lua/bindings/LuaBindingsRegistration.cpp')
-rw-r--r--src/config/lua/bindings/LuaBindingsRegistration.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/config/lua/bindings/LuaBindingsRegistration.cpp b/src/config/lua/bindings/LuaBindingsRegistration.cpp
new file mode 100644
index 00000000..ba6804a9
--- /dev/null
+++ b/src/config/lua/bindings/LuaBindingsRegistration.cpp
@@ -0,0 +1,66 @@
+#include "LuaBindingsInternal.hpp"
+
+#include "../objects/LuaEventSubscription.hpp"
+#include "../objects/LuaKeybind.hpp"
+#include "../objects/LuaLayerRule.hpp"
+#include "../objects/LuaNotification.hpp"
+#include "../objects/LuaTimer.hpp"
+#include "../objects/LuaWindowRule.hpp"
+
+using namespace Config;
+using namespace Config::Lua;
+using namespace Config::Lua::Bindings;
+
+static int hlPrint(lua_State* L) {
+ const int n = lua_gettop(L);
+ std::string out;
+ for (int i = 1; i <= n; i++) {
+ size_t len = 0;
+ const char* s = luaL_tolstring(L, i, &len);
+ if (i > 1)
+ out += '\t';
+ out.append(s, len);
+ lua_pop(L, 1);
+ }
+ Log::logger->log(Log::INFO, "[Lua] {}", out);
+ return 0;
+}
+
+void Internal::registerBindingsImpl(lua_State* L, CConfigManager* mgr) {
+ Objects::CLuaTimer{}.setup(L);
+ Objects::CLuaEventSubscription{}.setup(L);
+ Objects::CLuaWindowRule{}.setup(L);
+ Objects::CLuaLayerRule{}.setup(L);
+ Objects::CLuaKeybind{}.setup(L);
+ Objects::CLuaNotification{}.setup(L);
+
+ g_pKeybindManager->m_dispatchers["__lua"] = [L](std::string arg) -> SDispatchResult {
+ int ref = std::stoi(arg);
+ lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+
+ 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");
+ else
+ status = lua_pcall(L, 0, 0, 0);
+
+ if (status != LUA_OK) {
+ Config::Lua::mgr()->addError(std::format("error in keybind lambda: {}", lua_tostring(L, -1)));
+ lua_pop(L, 1);
+ }
+ return {};
+ };
+
+ lua_newtable(L);
+
+ Internal::registerConfigRuleBindings(L, mgr);
+ Internal::registerToplevelBindings(L, mgr);
+ Internal::registerQueryBindings(L);
+ Internal::registerDispatcherBindings(L);
+ Internal::registerNotificationBindings(L);
+
+ lua_setglobal(L, "hl");
+
+ lua_pushcfunction(L, hlPrint);
+ lua_setglobal(L, "print");
+}