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_queue.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/tangara/lua/lua_queue.cpp (limited to 'src/tangara/lua/lua_queue.cpp') diff --git a/src/tangara/lua/lua_queue.cpp b/src/tangara/lua/lua_queue.cpp new file mode 100644 index 00000000..dfb820c2 --- /dev/null +++ b/src/tangara/lua/lua_queue.cpp @@ -0,0 +1,74 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "lua_database.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 { + +[[maybe_unused]] static constexpr char kTag[] = "lua_queue"; + +static auto queue_add(lua_State* state) -> int { + Bridge* instance = Bridge::Get(state); + + if (lua_isinteger(state, 1)) { + database::TrackId id = luaL_checkinteger(state, 1); + instance->services().bg_worker().Dispatch([=]() { + audio::TrackQueue& queue = instance->services().track_queue(); + queue.append(id); + }); + } else { + database::Iterator* it = db_check_iterator(state, 1); + instance->services().bg_worker().Dispatch([=]() { + audio::TrackQueue& queue = instance->services().track_queue(); + queue.append(database::TrackIterator{*it}); + }); + } + + return 0; +} + +static auto queue_clear(lua_State* state) -> int { + Bridge* instance = Bridge::Get(state); + audio::TrackQueue& queue = instance->services().track_queue(); + queue.clear(); + return 0; +} + +static const struct luaL_Reg kQueueFuncs[] = {{"add", queue_add}, + {"clear", queue_clear}, + {NULL, NULL}}; + +static auto lua_queue(lua_State* state) -> int { + luaL_newlib(state, kQueueFuncs); + return 1; +} + +auto RegisterQueueModule(lua_State* s) -> void { + luaL_requiref(s, "queue", lua_queue, true); + lua_pop(s, 1); +} + +} // namespace lua -- cgit v1.2.3