summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Toso <me@victortoso.com>2016-03-03 01:17:43 +0100
committerVictor Toso <me@victortoso.com>2016-03-11 12:40:16 +0100
commit72a4e9d1924de741d66b4b5e4ed45e726db3913a (patch)
treeb40f39f15a157222261380a538804392c5d3dd3a
parentfc9cfe1dc167c6a7b843b91786e9d94b3d0b94a5 (diff)
lua-factory: use requested-keys as keys for lua api
We always provided the requested-keys to the lua source as an array with the metadata-keys as values. That's not so interesting as the source will need to walk in the array to check which keys were requested. As from commit 2bfcff90d589d43351 we started introducing the requested-keys as an argument, it would be good to use this moment and improve it. A table with the metadata-keys as key could be easily accessed in the source e.g if requested_keys.artist then media.artist = my_artist end https://bugzilla.gnome.org/show_bug.cgi?id=732879
-rw-r--r--src/lua-factory/grl-lua-library.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index dbcb4cd..a03a995 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -1612,16 +1612,22 @@ push_operation_requested_keys (lua_State *L,
lua_newtable (L);
for (it = keys; it != NULL; it = it->next) {
GrlKeyID key_id;
- const gchar *key_name;
+ char *key_name, *ptr;
key_id = GRLPOINTER_TO_KEYID (it->data);
if (key_id == GRL_METADATA_KEY_INVALID)
continue;
- key_name = grl_registry_lookup_metadata_key_name (registry, key_id);
- lua_pushinteger (L, i);
+ key_name = g_strdup (grl_registry_lookup_metadata_key_name (registry, key_id));
+ /* Replace '-' to '_': convenient for the developer */
+ while ((ptr = strstr (key_name, "-")) != NULL) {
+ *ptr = '_';
+ }
+
lua_pushstring (L, key_name);
+ lua_pushboolean (L, 1);
lua_settable (L, -3);
+ g_free (key_name);
i++;
}
}