diff --git a/modules/module-lua-scripting/pod.c b/modules/module-lua-scripting/pod.c index b9e10ba3..a9444aec 100644 --- a/modules/module-lua-scripting/pod.c +++ b/modules/module-lua-scripting/pod.c @@ -9,6 +9,8 @@ #include #include +#include + #define MAX_LUA_TYPES 9 /* Builder */ @@ -809,7 +811,7 @@ push_primitive_values (lua_State *L, WpSpaPod *pod, const gchar* type_name, } static void -push_luapod (lua_State *L, WpSpaPod *pod) +push_luapod (lua_State *L, WpSpaPod *pod, WpSpaIdValue field_idval) { /* None */ if (wp_spa_pod_is_none (pod)) { @@ -826,8 +828,17 @@ push_luapod (lua_State *L, WpSpaPod *pod) /* Id */ else if (wp_spa_pod_is_id (pod)) { guint32 value = 0; + WpSpaIdTable idtable = NULL; + WpSpaIdValue idval = NULL; wp_spa_pod_get_id (pod, &value); - lua_pushinteger (L, value); + if (field_idval && SPA_TYPE_Id == + wp_spa_id_value_get_value_type (field_idval, &idtable)) { + idval = wp_spa_id_table_find_value (idtable, value); + } + if (idval) + lua_pushstring (L, wp_spa_id_value_short_name (idval)); + else + lua_pushinteger (L, value); } /* Int */ @@ -918,13 +929,14 @@ push_luapod (lua_State *L, WpSpaPod *pod) /* Object */ else if (wp_spa_pod_is_object (pod)) { - const gchar *type_name = wp_spa_type_name (wp_spa_pod_get_spa_type (pod)); + WpSpaType type = wp_spa_pod_get_spa_type (pod); + WpSpaIdTable values_table = wp_spa_type_get_values_table (type); const gchar *id_name = NULL; g_auto (GValue) item = G_VALUE_INIT; g_autoptr (WpIterator) it = NULL; wp_spa_pod_get_object (pod, &id_name, NULL); lua_newtable (L); - lua_pushstring (L, type_name); + lua_pushstring (L, wp_spa_type_name (type)); lua_rawseti (L, -2, 0); lua_pushstring (L, id_name); lua_rawseti (L, -2, 1); @@ -933,8 +945,11 @@ push_luapod (lua_State *L, WpSpaPod *pod) WpSpaPod *prop = g_value_get_boxed (&item); const gchar *key = NULL; g_autoptr (WpSpaPod) val = NULL; + //FIXME: this is suboptimal because _get_property() converts + // the key to a short name and we convert it back wp_spa_pod_get_property (prop, &key, &val); - push_luapod (L, val); + push_luapod (L, val, + wp_spa_id_table_find_value_from_short_name (values_table, key)); lua_setfield (L, -2, key); } } @@ -947,7 +962,7 @@ push_luapod (lua_State *L, WpSpaPod *pod) lua_newtable (L); for (; wp_iterator_next (it, &item); g_value_unset (&item)) { WpSpaPod *val = g_value_get_boxed (&item); - push_luapod (L, val); + push_luapod (L, val, NULL); lua_rawseti (L, -2, i++); } } @@ -969,7 +984,7 @@ push_luapod (lua_State *L, WpSpaPod *pod) lua_setfield (L, -2, "offset"); lua_pushstring (L, type_name); lua_setfield (L, -2, "typename"); - push_luapod (L, val); + push_luapod (L, val, NULL); lua_setfield (L, -2, "value"); lua_rawseti (L, -2, i++); } @@ -1008,7 +1023,7 @@ static int spa_pod_parse (lua_State *L) { WpSpaPod *pod = wplua_checkboxed (L, 1, WP_TYPE_SPA_POD); - push_luapod (L, pod); + push_luapod (L, pod, NULL); return 1; } diff --git a/tests/wplua/scripts/pod.lua b/tests/wplua/scripts/pod.lua index 1256fa2f..342ae0da 100644 --- a/tests/wplua/scripts/pod.lua +++ b/tests/wplua/scripts/pod.lua @@ -83,8 +83,8 @@ pod = Pod.Object { val = pod:parse() assert (val[0] == "Spa:Pod:Object:Param:PortConfig") assert (val[1] == "PortConfig") -assert (val.direction == 0) -assert (val.mode == 3) +assert (val.direction == "Input") +assert (val.mode == "dsp") assert (val.monitor) assert (pod:get_type_name() == "Spa:Pod:Object:Param:PortConfig") @@ -138,11 +138,11 @@ pod = Pod.Object { val = pod:parse() assert (val[0] == "Spa:Pod:Object:Param:PortConfig") assert (val[1] == "PortConfig") -assert (val.direction == 0) -assert (val.mode == 3) +assert (val.direction == "Input") +assert (val.mode == "dsp") assert (val.monitor) -assert (val.format.mediaType == 1) -assert (val.format.mediaSubtype == 1) +assert (val.format.mediaType == "audio") +assert (val.format.mediaSubtype == "raw") assert (val.format.rate == 48000) assert (val.format.channels == 2) assert (val.format.position[0] == "Spa:Id" and val.format.position[1] == 0 and val.format.position[2] == 1)