mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-08 15:08:04 +02:00
wplua: gvariant_to_lua: convert dictionary keys to integers if possible
When we convert from a lua table to a GVariant dictionary, it is not
possible to maintain the hybrid string & integer keys approach that Lua
has for tables, so we convert all keys to strings and a table becomes a{sv}
When we convert back from a{sv} to a table, it is desirable to get back
the integer keys wherever possible.
The use case is to pass "arrays" (i.e. tables with integer keys) from
the configuration files to the lua scripts, without losing the properties
of the "array"
This commit is contained in:
parent
73a07d0097
commit
e92351b23b
1 changed files with 9 additions and 0 deletions
|
|
@ -130,6 +130,15 @@ wplua_gvariant_to_lua (lua_State *L, GVariant *variant)
|
|||
g_autoptr (GVariant) key, value;
|
||||
g_variant_get_child (variant, i, "{@?@*}", &key, &value);
|
||||
wplua_gvariant_to_lua (L, key);
|
||||
/* if the key is a string convertible to integer, convert it */
|
||||
if (lua_type (L, -1) == LUA_TSTRING) {
|
||||
int isnum = 0;
|
||||
lua_Integer num = lua_tointegerx (L, -1, &isnum);
|
||||
if (isnum) {
|
||||
lua_pop (L, 1);
|
||||
lua_pushinteger (L, num);
|
||||
}
|
||||
}
|
||||
wplua_gvariant_to_lua (L, value);
|
||||
lua_settable (L, -3);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue