[grilo-plugins] lua-factory: Make it easier to access the API key config



commit 89cae5ee5f19f00dda9e868742ad97c6e1bdf6e5
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Jun 13 01:52:13 2015 +0200

    lua-factory: Make it easier to access the API key config
    
    Eg. configs.api_key is available as well as configs['api-key'].
    
    https://bugzilla.gnome.org/show_bug.cgi?id=750903

 src/lua-factory/grl-lua-factory.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-factory.c b/src/lua-factory/grl-lua-factory.c
index b092bb0..1077da6 100644
--- a/src/lua-factory/grl-lua-factory.c
+++ b/src/lua-factory/grl-lua-factory.c
@@ -435,6 +435,23 @@ lua_plugin_source_init (GrlLuaFactorySource *lua_source)
         lua_pushstring (L, key);
         lua_pushstring (L, value);
         lua_settable (L, -3);
+
+        /* Also add the underscore version of the key if necessary,
+         * eg. configs.api_key is available as well as configs['api-key'] */
+        if (strchr (key, '-') != NULL) {
+          char *lua_key;
+          char *ptr = NULL;
+
+          lua_key = g_strdup (key);
+          while ((ptr = strchr (lua_key, '-')) != NULL)
+            *ptr = '_';
+
+          lua_pushstring (L, lua_key);
+          lua_pushstring (L, value);
+          lua_settable (L, -3);
+
+          g_free (lua_key);
+        }
       }
     }
     g_list_free (list_keys);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]