From 01eb8683733f39a6de984111f035bb8f71dcf8b8 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 12 Dec 2023 12:59:38 +1100 Subject: Support more datatypes in track tags --- src/lua/property.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/lua') diff --git a/src/lua/property.cpp b/src/lua/property.cpp index b424a866..7a45552b 100644 --- a/src/lua/property.cpp +++ b/src/lua/property.cpp @@ -5,6 +5,7 @@ */ #include "property.hpp" +#include #include #include @@ -160,6 +161,29 @@ Property::Property(const LuaValue& val, std::function cb) : value_(val), cb_(cb) {} +static auto pushTagValue(lua_State* L, const database::TagValue& val) -> void { + std::visit( + [&](auto&& arg) { + using T = std::decay_t; + if constexpr (std::is_same_v) { + lua_pushlstring(L, arg.data(), arg.size()); + } else if constexpr (std::is_same_v< + T, cpp::span>) { + lua_createtable(L, 0, arg.size()); + for (const auto& i : arg) { + lua_pushlstring(L, i.data(), i.size()); + lua_pushboolean(L, true); + lua_rawset(L, -2); + } + } else if constexpr (std::is_same_v) { + lua_pushinteger(L, arg); + } else { + lua_pushnil(L); + } + }, + val); +} + auto Property::PushValue(lua_State& s) -> int { std::visit( [&](auto&& arg) { @@ -177,9 +201,9 @@ auto Property::PushValue(lua_State& s) -> int { } 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()); + for (const auto& tag : arg.tags->allPresent()) { + lua_pushstring(&s, database::tagName(tag).c_str()); + pushTagValue(&s, arg.tags->get(tag)); lua_settable(&s, table); } if (arg.db_info) { -- cgit v1.2.3