diff --git a/modules/module-lua-scripting/pod.c b/modules/module-lua-scripting/pod.c index 770a137c9d9cc75794c713f89818ac3e3aa8aec3..e152d0affc9ad78eb899abfe12684325dae970a6 100644 --- a/modules/module-lua-scripting/pod.c +++ b/modules/module-lua-scripting/pod.c @@ -335,9 +335,33 @@ spa_pod_boolean_new (lua_State *L) static int spa_pod_id_new (lua_State *L) { - gint64 value = lua_tointeger (L, 1); - wplua_pushboxed (L, WP_TYPE_SPA_POD, wp_spa_pod_new_id (value)); - return 1; + /* Id number */ + if (lua_type (L, 1) == LUA_TNUMBER) { + gint64 value = lua_tointeger (L, 1); + wplua_pushboxed (L, WP_TYPE_SPA_POD, wp_spa_pod_new_id (value)); + return 1; + } + + /* Table name and key name */ + else if (lua_type (L, 1) == LUA_TSTRING) { + const gchar *table_name = lua_tostring (L, 1); + const gchar *key_name = lua_tostring (L, 2); + WpSpaIdTable table = NULL; + WpSpaIdValue value = NULL; + table = wp_spa_id_table_from_name (table_name); + if (!table) + luaL_error (L, "table '%s' does not exist", table_name); + value = wp_spa_id_table_find_value_from_short_name (table, key_name); + if (!value) + luaL_error (L, "key '%s' does not exist in '%s'", key_name, table_name); + wplua_pushboxed (L, WP_TYPE_SPA_POD, + wp_spa_pod_new_id (wp_spa_id_value_number (value))); + return 1; + } + + /* Error */ + luaL_error (L, "Invalid parameters"); + return 0; } /* Int */ diff --git a/tests/wplua/scripts/pod.lua b/tests/wplua/scripts/pod.lua index 4356e7f2d827f6311f672140dd36cc9ab9a6e271..a8f63c80d11ca030885f860ef44ed2b8860187cd 100644 --- a/tests/wplua/scripts/pod.lua +++ b/tests/wplua/scripts/pod.lua @@ -12,6 +12,9 @@ assert (pod:get_type_name() == "Spa:Bool") pod = Pod.Id (4) assert (pod:parse() == 4) assert (pod:get_type_name() == "Spa:Id") +pod = Pod.Id("Spa:Enum:AudioChannel", "FL") +assert (pod:parse() == 3) +assert (pod:get_type_name() == "Spa:Id") -- Int pod = Pod.Int (64)