summaryrefslogtreecommitdiff
path: root/src/tangara/lua/lua_queue.cpp
diff options
context:
space:
mode:
authorcooljqln <cooljqln@noreply.codeberg.org>2024-05-03 04:48:17 +0000
committercooljqln <cooljqln@noreply.codeberg.org>2024-05-03 04:48:17 +0000
commit3ceb8025ee4330c177101ed30ec17dfb0002f41e (patch)
tree58350210f15df7d00d967cac6f30eeceeb031a3c /src/tangara/lua/lua_queue.cpp
parent964da15a0b84f8e5f00e8abac2f7dfda0bf60488 (diff)
parent9fafd797a5504f458b5fcae4a1d28a68da936315 (diff)
downloadtangara-fw-3ceb8025ee4330c177101ed30ec17dfb0002f41e.tar.gz
Merge pull request 'Break dependency cycles with our components by merging co-dependent components together' (#68) from jqln/component-merge into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/68
Diffstat (limited to 'src/tangara/lua/lua_queue.cpp')
-rw-r--r--src/tangara/lua/lua_queue.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/tangara/lua/lua_queue.cpp b/src/tangara/lua/lua_queue.cpp
new file mode 100644
index 00000000..bc393aa5
--- /dev/null
+++ b/src/tangara/lua/lua_queue.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#include "lua/lua_database.hpp"
+
+#include <memory>
+#include <string>
+
+#include "lua.hpp"
+
+#include "esp_log.h"
+#include "lauxlib.h"
+#include "lua.h"
+#include "lvgl.h"
+
+#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 {
+
+[[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<void>([=]() {
+ audio::TrackQueue& queue = instance->services().track_queue();
+ queue.append(id);
+ });
+ } else {
+ database::Iterator* it = db_check_iterator(state, 1);
+ instance->services().bg_worker().Dispatch<void>([=]() {
+ 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