From 1573a8c4cde1cd9528b422b2dcc598e37ffe94a7 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 19:12:26 +1000 Subject: WIP merge cyclically dependent components into one big component --- src/tangara/lua/lua_screen.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/tangara/lua/lua_screen.cpp (limited to 'src/tangara/lua/lua_screen.cpp') diff --git a/src/tangara/lua/lua_screen.cpp b/src/tangara/lua/lua_screen.cpp new file mode 100644 index 00000000..f17f6b1a --- /dev/null +++ b/src/tangara/lua/lua_screen.cpp @@ -0,0 +1,79 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "lua_screen.hpp" + +#include +#include + +#include "lua.hpp" + +#include "esp_log.h" +#include "lauxlib.h" +#include "lua.h" +#include "lvgl.h" + +#include "bridge.hpp" +#include "database.hpp" +#include "event_queue.hpp" +#include "index.hpp" +#include "property.hpp" +#include "service_locator.hpp" +#include "track.hpp" +#include "track_queue.hpp" +#include "ui_events.hpp" + +namespace lua { + +static auto screen_new(lua_State* L) -> int { + // o = o or {} + if (lua_gettop(L) != 2) { + lua_settop(L, 1); + lua_newtable(L); + } + // Swap o and self on the stack. + lua_insert(L, 1); + + lua_pushliteral(L, "__index"); + lua_pushvalue(L, 1); + lua_settable(L, 1); // self.__index = self + + lua_setmetatable(L, 1); // setmetatable(o, self) + + return 1; // return o +} + +static auto screen_noop(lua_State* state) -> int { + return 0; +} + +static auto screen_true(lua_State* state) -> int { + lua_pushboolean(state, true); + return 1; +} + +static const struct luaL_Reg kScreenFuncs[] = { + {"new", screen_new}, {"createUi", screen_noop}, + {"onShown", screen_noop}, {"onHidden", screen_noop}, + {"canPop", screen_true}, {NULL, NULL}}; + +static auto lua_screen(lua_State* state) -> int { + luaL_newlib(state, kScreenFuncs); + + lua_pushliteral(state, "__index"); + lua_pushvalue(state, -2); + lua_rawset(state, -3); + + return 1; +} + +auto RegisterScreenModule(lua_State* s) -> void { + luaL_requiref(s, "screen", lua_screen, true); + + lua_pop(s, 1); +} + +} // namespace lua -- cgit v1.2.3 From 7d7f7755d17e1e0a2348d75d797097f166b70471 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 21:41:56 +1000 Subject: start moving include files into subdirs --- src/tangara/lua/lua_screen.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/tangara/lua/lua_screen.cpp') diff --git a/src/tangara/lua/lua_screen.cpp b/src/tangara/lua/lua_screen.cpp index f17f6b1a..8d87eebd 100644 --- a/src/tangara/lua/lua_screen.cpp +++ b/src/tangara/lua/lua_screen.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-only */ -#include "lua_screen.hpp" +#include "lua/lua_screen.hpp" #include #include @@ -16,15 +16,15 @@ #include "lua.h" #include "lvgl.h" -#include "bridge.hpp" -#include "database.hpp" -#include "event_queue.hpp" -#include "index.hpp" -#include "property.hpp" -#include "service_locator.hpp" -#include "track.hpp" -#include "track_queue.hpp" -#include "ui_events.hpp" +#include "audio/track_queue.hpp" +#include "database/database.hpp" +#include "database/index.hpp" +#include "database/track.hpp" +#include "events/event_queue.hpp" +#include "lua/bridge.hpp" +#include "lua/property.hpp" +#include "system_fsm/service_locator.hpp" +#include "ui/ui_events.hpp" namespace lua { -- cgit v1.2.3