From 9b2cd6b9853d7eb0be04799fe95b9ffddbde4659 Mon Sep 17 00:00:00 2001 From: buffet Date: Fri, 18 Oct 2019 23:32:29 +0200 Subject: [PATCH] Add Lua config without kiwmi lib --- include/luak.h | 19 +++++++++++++++++++ include/server.h | 3 +++ kiwmi/luak.c | 27 +++++++++++++++++++++++++++ kiwmi/meson.build | 2 ++ kiwmi/server.c | 15 +++++++++++++++ meson.build | 1 + 6 files changed, 67 insertions(+) create mode 100644 include/luak.h create mode 100644 kiwmi/luak.c diff --git a/include/luak.h b/include/luak.h new file mode 100644 index 0000000..eed0fe9 --- /dev/null +++ b/include/luak.h @@ -0,0 +1,19 @@ +/* Copyright (c), Niclas 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 2e74f5a..4db8e2c 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..b6f9f4b --- /dev/null +++ b/kiwmi/luak.c @@ -0,0 +1,27 @@ +/* Copyright (c), Niclas 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 f7a25d7..d8e58a8 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')