Add luaK_fini

This commit is contained in:
buffet 2019-12-31 00:09:06 +00:00
parent 1d073cf0ea
commit 9fb2b2ce43
3 changed files with 26 additions and 0 deletions

View file

@ -16,9 +16,11 @@
struct kiwmi_lua {
lua_State *L;
struct wl_list callbacks; // lua_callback::link
};
bool luaK_init(struct kiwmi_server *server);
bool luaK_dofile(struct kiwmi_lua *lua, const char *config_path);
void luaK_fini(struct kiwmi_lua *lua);
#endif /* KIWMI_LUAK_H */

View file

@ -21,6 +21,7 @@
#include "input/input.h"
struct lua_callback {
struct wl_list link;
struct kiwmi_server *server;
int callback_ref;
struct wl_listener listener;
@ -34,6 +35,8 @@ l_lua_callback_cancel(lua_State *L)
lua_pop(L, 1);
wl_list_remove(&lc->listener.link);
wl_list_remove(&lc->link);
free(lc);
return 0;
@ -170,6 +173,8 @@ on_cursor_button(lua_State *L)
struct kiwmi_server *server = get_server(L);
struct kiwmi_cursor *cursor = server->input.cursor;
wl_list_insert(&server->lua->callbacks, &lc->link);
lc->server = server;
lc->callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
@ -269,6 +274,8 @@ luaK_init(struct kiwmi_server *server)
lua->L = L;
server->lua = lua;
wl_list_init(&lua->callbacks);
return true;
}
@ -283,3 +290,18 @@ luaK_dofile(struct kiwmi_lua *lua, const char *config_path)
return true;
}
void
luaK_fini(struct kiwmi_lua *lua)
{
struct lua_callback *lc;
struct lua_callback *tmp;
wl_list_for_each_safe(lc, tmp, &lua->callbacks, link) {
wl_list_remove(&lc->listener.link);
wl_list_remove(&lc->link);
free(lc);
}
lua_close(lua->L);
}

View file

@ -128,5 +128,7 @@ server_fini(struct kiwmi_server *server)
wl_display_destroy_clients(server->wl_display);
wl_display_destroy(server->wl_display);
luaK_fini(server->lua);
free(server->config_path);
}