From c3fd6d2f855627a2ff9a2e5135d32c636b24d6fa Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 22 Mar 2026 17:43:54 -0700 Subject: [PATCH] feat: add keybinding query API for action bar tooltips and binding UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement GetBindingKey(command) and GetBindingAction(key) with default action button mappings (ACTIONBUTTON1-12 → "1"-"9","0","-","="). Action bar addons display bound keys on button tooltips via GetBindingKey("ACTIONBUTTON"..slot). Also add stubs for GetNumBindings, GetBinding, SetBinding, SaveBindings, SetOverrideBindingClick, and ClearOverrideBindings to prevent nil-call errors in FrameXML keybinding UI code (37 call sites). --- src/addons/lua_engine.cpp | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index 7dc2a9d5..adabba49 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -4284,6 +4284,59 @@ static int lua_GetModifiedClick(lua_State* L) { } static int lua_SetModifiedClick(lua_State* L) { (void)L; return 0; } +// --- Keybinding API --- +// Maps WoW binding names like "ACTIONBUTTON1" to key display strings like "1" + +// GetBindingKey(command) → key1, key2 (or nil) +static int lua_GetBindingKey(lua_State* L) { + const char* cmd = luaL_checkstring(L, 1); + std::string command(cmd); + // Return intuitive default bindings for action buttons + if (command.find("ACTIONBUTTON") == 0) { + std::string num = command.substr(12); + int n = 0; + try { n = std::stoi(num); } catch(...) {} + if (n >= 1 && n <= 9) { + lua_pushstring(L, num.c_str()); + return 1; + } else if (n == 10) { + lua_pushstring(L, "0"); + return 1; + } else if (n == 11) { + lua_pushstring(L, "-"); + return 1; + } else if (n == 12) { + lua_pushstring(L, "="); + return 1; + } + } + lua_pushnil(L); + return 1; +} + +// GetBindingAction(key) → command (or nil) +static int lua_GetBindingAction(lua_State* L) { + const char* key = luaL_checkstring(L, 1); + std::string k(key); + // Simple reverse mapping for number keys + if (k.size() == 1 && k[0] >= '1' && k[0] <= '9') { + lua_pushstring(L, ("ACTIONBUTTON" + k).c_str()); + return 1; + } else if (k == "0") { + lua_pushstring(L, "ACTIONBUTTON10"); + return 1; + } + lua_pushnil(L); + return 1; +} + +static int lua_GetNumBindings(lua_State* L) { lua_pushnumber(L, 0); return 1; } +static int lua_GetBinding(lua_State* L) { (void)L; lua_pushnil(L); return 1; } +static int lua_SetBinding(lua_State* L) { (void)L; return 0; } +static int lua_SaveBindings(lua_State* L) { (void)L; return 0; } +static int lua_SetOverrideBindingClick(lua_State* L) { (void)L; return 0; } +static int lua_ClearOverrideBindings(lua_State* L) { (void)L; return 0; } + // Frame methods: SetPoint, SetSize, SetWidth, SetHeight, GetWidth, GetHeight, GetCenter, SetAlpha, GetAlpha static int lua_Frame_SetPoint(lua_State* L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -4613,6 +4666,14 @@ void LuaEngine::registerCoreAPI() { {"IsModifiedClick", lua_IsModifiedClick}, {"GetModifiedClick", lua_GetModifiedClick}, {"SetModifiedClick", lua_SetModifiedClick}, + {"GetBindingKey", lua_GetBindingKey}, + {"GetBindingAction", lua_GetBindingAction}, + {"GetNumBindings", lua_GetNumBindings}, + {"GetBinding", lua_GetBinding}, + {"SetBinding", lua_SetBinding}, + {"SaveBindings", lua_SaveBindings}, + {"SetOverrideBindingClick", lua_SetOverrideBindingClick}, + {"ClearOverrideBindings", lua_ClearOverrideBindings}, {"SendChatMessage", lua_SendChatMessage}, {"SendAddonMessage", lua_SendAddonMessage}, {"RegisterAddonMessagePrefix", lua_RegisterAddonMessagePrefix},