diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-11-23 14:08:46 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-11-23 14:08:46 +1100 |
| commit | 09c0e1608f2d88f56d8bf87ff90482459376ad95 (patch) | |
| tree | e675756aff8c8f78fe89c4f2f9e30c713f10cbfe /src/lua/lua_queue.cpp | |
| parent | b07bfbc6c70fd0bba8dff85fe4149feb9fa9b8d4 (diff) | |
| download | tangara-fw-09c0e1608f2d88f56d8bf87ff90482459376ad95.tar.gz | |
Implement adding to the playback queue from lua
Diffstat (limited to 'src/lua/lua_queue.cpp')
| -rw-r--r-- | src/lua/lua_queue.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/lua/lua_queue.cpp b/src/lua/lua_queue.cpp index 500940a2..929a7159 100644 --- a/src/lua/lua_queue.cpp +++ b/src/lua/lua_queue.cpp @@ -21,6 +21,7 @@ #include "index.hpp" #include "property.hpp" #include "service_locator.hpp" +#include "source.hpp" #include "ui_events.hpp" namespace lua { @@ -28,10 +29,28 @@ 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)) { + instance->services().track_queue().AddLast(luaL_checkinteger(state, 1)); + } else { + database::Iterator* it = db_check_iterator(state, 1); + instance->services().track_queue().IncludeLast( + std::make_shared<playlist::IteratorSource>(*it)); + } + + return 0; +} + +static auto queue_clear(lua_State* state) -> int { + Bridge* instance = Bridge::Get(state); + instance->services().track_queue().Clear(); return 0; } -static const struct luaL_Reg kQueueFuncs[] = {{"add", queue_add}, {NULL, NULL}}; +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); |
