From 7c6eb2997cbba350e7384151e13659271508e08f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 24 Nov 2023 15:13:10 +1100 Subject: Migrate 'now playing' screen to lua --- src/lua/property.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/lua/property.cpp') diff --git a/src/lua/property.cpp b/src/lua/property.cpp index c63d243f..3e492237 100644 --- a/src/lua/property.cpp +++ b/src/lua/property.cpp @@ -9,10 +9,13 @@ #include #include +#include "lua.h" #include "lua.hpp" #include "lua_thread.hpp" #include "lvgl.h" #include "service_locator.hpp" +#include "track.hpp" +#include "types.hpp" namespace lua { @@ -51,7 +54,7 @@ static auto property_bind(lua_State* state) -> int { lua_pushvalue(state, 2); p->PushValue(*state); - CallProtected(state, 1, 0); // Invoke the initial binding. + CallProtected(state, 1, 0); // Invoke the initial binding. lua_pushstring(state, kBindingsTable); lua_gettable(state, LUA_REGISTRYINDEX); // REGISTRY[kBindingsTable] @@ -171,6 +174,31 @@ auto Property::PushValue(lua_State& s) -> int { lua_pushboolean(&s, arg); } else if constexpr (std::is_same_v) { lua_pushstring(&s, arg.c_str()); + } else if constexpr (std::is_same_v) { + lua_newtable(&s); + int table = lua_gettop(&s); + for (const auto& [key, val] : arg.tags->tags()) { + lua_pushstring(&s, database::TagToString(key).c_str()); + lua_pushstring(&s, val.c_str()); + lua_settable(&s, table); + } + if (arg.db_info) { + lua_pushliteral(&s, "id"); + lua_pushinteger(&s, arg.db_info->id); + lua_settable(&s, table); + } + + lua_pushliteral(&s, "duration"); + lua_pushinteger(&s, arg.duration); + lua_settable(&s, table); + + lua_pushliteral(&s, "bitrate_kbps"); + lua_pushinteger(&s, arg.bitrate_kbps); + lua_settable(&s, table); + + lua_pushliteral(&s, "encoding"); + lua_pushstring(&s, codecs::StreamTypeToString(arg.encoding).c_str()); + lua_settable(&s, table); } else { static_assert(always_false_v, "PushValue missing type"); } @@ -228,8 +256,8 @@ auto Property::Update(const LuaValue& v) -> void { continue; } - PushValue(*b.first); // push the argument - CallProtected(b.first, 1, 0); // invoke the closure + PushValue(*b.first); // push the argument + CallProtected(b.first, 1, 0); // invoke the closure } } -- cgit v1.2.3