m-lua-scripting: add support for choices when creating object pods
This commit is contained in:

committed by
George Kiagiadakis

parent
0694889245
commit
bd65f9578d
@@ -252,6 +252,24 @@ builder_add_fd_lua_string (WpSpaPodBuilder *b, WpSpaIdValue key_id,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
is_pod_type_compatible (WpSpaType type, WpSpaPod *pod)
|
||||
{
|
||||
/* Check if the pod type matches */
|
||||
if (type == wp_spa_pod_get_spa_type (pod))
|
||||
return TRUE;
|
||||
|
||||
/* Otherwise, check if the child type of Choice pod matches */
|
||||
if (wp_spa_pod_is_choice (pod)) {
|
||||
g_autoptr (WpSpaPod) child = wp_spa_pod_get_choice_child (pod);
|
||||
WpSpaType child_type = wp_spa_pod_get_spa_type (child);
|
||||
if (type == child_type)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
builder_add_lua_userdata (WpSpaPodBuilder *b, WpSpaIdValue key_id,
|
||||
lua_State *L, int idx)
|
||||
@@ -259,7 +277,7 @@ builder_add_lua_userdata (WpSpaPodBuilder *b, WpSpaIdValue key_id,
|
||||
WpSpaPod *pod = wplua_checkboxed (L, idx, WP_TYPE_SPA_POD);
|
||||
if (pod) {
|
||||
WpSpaType prop_type = wp_spa_id_value_get_value_type (key_id, NULL);
|
||||
if (prop_type == wp_spa_pod_get_spa_type (pod)) {
|
||||
if (is_pod_type_compatible (prop_type, pod)) {
|
||||
wp_spa_pod_builder_add_pod (b, pod);
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -175,7 +175,7 @@ pod = Pod.Object {
|
||||
mediaType = "audio",
|
||||
mediaSubtype = "raw",
|
||||
rate = 48000,
|
||||
channels = 2,
|
||||
channels = Pod.Choice.Range { "Spa:Int", 2, 1, 32 },
|
||||
position = Pod.Array { "Spa:Enum:AudioChannel", "FL", "FR" }
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,11 @@ assert (val.properties.format.id_type == "Format")
|
||||
assert (val.properties.format.properties.mediaType == "audio")
|
||||
assert (val.properties.format.properties.mediaSubtype == "raw")
|
||||
assert (val.properties.format.properties.rate == 48000)
|
||||
assert (val.properties.format.properties.channels == 2)
|
||||
assert (val.properties.format.properties.channels.pod_type == "Choice.Range")
|
||||
assert (val.properties.format.properties.channels.value_type == "Spa:Int")
|
||||
assert (val.properties.format.properties.channels[1] == 2)
|
||||
assert (val.properties.format.properties.channels[2] == 1)
|
||||
assert (val.properties.format.properties.channels[3] == 32)
|
||||
assert (val.properties.format.properties.position.pod_type == "Array")
|
||||
assert (val.properties.format.properties.position.value_type == "Spa:Id")
|
||||
assert (val.properties.format.properties.position[1] == 3 and val.properties.format.properties.position[2] == 4)
|
||||
|
Reference in New Issue
Block a user