Fix crashing

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-08-10 08:45:45 +03:00
parent ab7ca71ba2
commit ad0d09ebd2
3 changed files with 79 additions and 88 deletions

View File

@@ -263,33 +263,19 @@ void config_unref(lua_State *L, Config *cfg)
cfg->input.keyboard.xkb_options = NULL;
}
int trigger_ref_modsym(
lua_State *L, Config const *cfg, uint32_t mods, xkb_keysym_t sym)
void config_trigger_ref(lua_State *L, Config *cfg, int ref)
{
if (!L || !cfg)
return -1;
for (size_t i = 0; i < cfg->keybindings.count; ++i) {
BindingRef const *br = &cfg->keybindings.items[i];
if (br->sym != sym)
continue;
if ((mods & br->mods_mask) != br->mods_mask)
continue;
lua_rawgeti(L, LUA_REGISTRYINDEX, br->action_ref);
if (!lua_isfunction(L, -1)) {
lua_pop(L, 1);
return -2;
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
fprintf(stderr, "config: action error: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
return -3;
}
return 0;
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
if (!lua_isfunction(L, -1)) {
lua_pop(L, 1);
return;
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
fprintf(stderr, "config: action error: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
return;
}
return 1;
}
static int load_config_file(lua_State *L, char const *path)