Skip to content
Snippets Groups Projects
Commit e92351b2 authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

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"
parent 73a07d00
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment