[grilo-plugins/wip/jfelder/lua-grl-related-keys: 119/121] lua-factory: Handle numerical indexes in lua-json



commit 91bf2dceccdb43b025948069f5743847982cd566
Author: Jean Felder <jfelder src gnome org>
Date:   Fri May 1 22:24:22 2020 +0200

    lua-factory: Handle numerical indexes in lua-json
    
    This allows to handle nested arrays in a lua table.

 src/lua-factory/lua-library/lua-json.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/lua-factory/lua-library/lua-json.c b/src/lua-factory/lua-library/lua-json.c
index d22ee3b8..bbf01f27 100644
--- a/src/lua-factory/lua-library/lua-json.c
+++ b/src/lua-factory/lua-library/lua-json.c
@@ -53,8 +53,14 @@ build_table_from_json_reader (lua_State *L,
 
   } else if (lua_istable (L, -1)) {
     const gchar *member_name = json_reader_get_member_name (reader);
-    if (member_name)
-      lua_pushstring (L, member_name);
+    if (member_name) {
+      gint64 member_int = g_ascii_strtoll(member_name, NULL, 0);
+      if (member_int) {
+        lua_pushinteger (L, member_int);
+      } else {
+        lua_pushstring (L, member_name);
+      }
+    }
 
   } else if (!lua_isnumber (L, -1)) {
     GRL_DEBUG ("getting value to either table or array");


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