diff --git a/include/luak.h b/include/luak.h new file mode 100644 index 0000000..399ccc8 --- /dev/null +++ b/include/luak.h @@ -0,0 +1,19 @@ +/* Copyright (c), Charlotte Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#ifndef KIWMI_LUAK_H +#define KIWMI_LUAK_H + +#include + +#include + +#include "server.h" + +bool luaK_init(struct kiwmi_server *server); + +#endif /* KIWMI_LUAK_H */ diff --git a/include/server.h b/include/server.h index d10841c..c183949 100644 --- a/include/server.h +++ b/include/server.h @@ -10,6 +10,8 @@ #include +#include + #include "desktop/desktop.h" #include "input/input.h" @@ -19,6 +21,7 @@ struct kiwmi_server { struct wlr_backend *backend; const char *socket; char *config_path; + lua_State *L; struct kiwmi_desktop desktop; struct kiwmi_input input; }; diff --git a/kiwmi/luak.c b/kiwmi/luak.c new file mode 100644 index 0000000..48522f2 --- /dev/null +++ b/kiwmi/luak.c @@ -0,0 +1,27 @@ +/* Copyright (c), Charlotte Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include "luak.h" + +#include +#include + +bool +luaK_init(struct kiwmi_server *server) +{ + lua_State *L = luaL_newstate(); + if (!L) { + return false; + } + + luaL_openlibs(L); + + // TODO: kiwmi library + + server->L = L; + return true; +} diff --git a/kiwmi/meson.build b/kiwmi/meson.build index 489b970..8cf75aa 100644 --- a/kiwmi/meson.build +++ b/kiwmi/meson.build @@ -1,4 +1,5 @@ kiwmi_sources = files( + 'luak.c', 'main.c', 'server.c', 'desktop/desktop.c', @@ -9,6 +10,7 @@ kiwmi_sources = files( ) kiwmi_deps = [ + lua, wayland_server, wlroots, xkbcommon, diff --git a/kiwmi/server.c b/kiwmi/server.c index 5637eb7..c4e427b 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -12,11 +12,14 @@ #include +#include #include #include #include #include +#include "luak.h" + bool server_init(struct kiwmi_server *server, char *config_path) { @@ -73,6 +76,12 @@ server_init(struct kiwmi_server *server, char *config_path) server->config_path = config_path; + if (!luaK_init(server)) { + wlr_log(WLR_ERROR, "Failed to initialize Lua"); + wl_display_destroy(server->wl_display); + return false; + } + return true; } @@ -90,6 +99,12 @@ server_run(struct kiwmi_server *server) setenv("WAYLAND_DISPLAY", server->socket, true); + if (luaL_dofile(server->L, server->config_path)) { + wlr_log(WLR_ERROR, "Error running config: %s", lua_tostring(server->L, -1)); + wl_display_destroy(server->wl_display); + return false; + } + wl_display_run(server->wl_display); return true; diff --git a/meson.build b/meson.build index 5c3586d..883f53f 100644 --- a/meson.build +++ b/meson.build @@ -17,6 +17,7 @@ add_project_arguments( ) git = find_program('git', required: false) +lua = dependency('lua') wayland_server = dependency('wayland-server') wlroots = dependency('wlroots') xkbcommon = dependency('xkbcommon')