[grilo-plugins] lua-factory: Stricter integer typization for Lua



commit 8b18594e65fc1196c1d270ee3fcefe55195ea397
Author: George Sedov <radist morse gmail com>
Date:   Wed Aug 5 01:38:55 2015 +0300

    lua-factory: Stricter integer typization for Lua
    
    Lua 5.3 introduced a new integer type to Lua. Now it should be used
    instead of previous "number" whenever applicable.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753141

 configure.ac                           |    4 +-
 src/lua-factory/grl-lua-factory.c      |    2 +-
 src/lua-factory/grl-lua-library.c      |   42 ++++++++++++++++----------------
 src/lua-factory/lua-library/lua-json.c |    4 +-
 4 files changed, 26 insertions(+), 26 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0e1353f..7112cf1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,9 +130,9 @@ PKG_CHECK_MODULES(GDATA, libgdata >= 0.9.1, HAVE_GDATA=yes, HAVE_GDATA=no)
 
 PKG_CHECK_MODULES(LIBSOUP, libsoup-2.4, HAVE_LIBSOUP=yes, HAVE_LIBSOUP=no)
 
-PKG_CHECK_MODULES(LUA, lua >= 5.2.0,
+PKG_CHECK_MODULES(LUA, lua >= 5.3.0,
                        HAVE_LUA=yes,
-                       [PKG_CHECK_MODULES(LUA, lua5.2 >= 5.2.0,
+                       [PKG_CHECK_MODULES(LUA, lua5.3 >= 5.3.0,
                                                HAVE_LUA=yes,
                                                HAVE_LUA=no)])
 
diff --git a/src/lua-factory/grl-lua-factory.c b/src/lua-factory/grl-lua-factory.c
index f3b1e16..1b18ca4 100644
--- a/src/lua-factory/grl-lua-factory.c
+++ b/src/lua-factory/grl-lua-factory.c
@@ -1274,7 +1274,7 @@ lua_plugin_source_info (lua_State *L,
 
   /* Auto-split-threshold */
   lua_getfield (L, -6, LUA_SOURCE_AUTO_SPLIT_THRESHOLD);
-  lua_auto_split_threshold = lua_tonumber (L, -1);
+  lua_auto_split_threshold = lua_tointeger (L, -1);
 
   /* Source Tags */
   lua_getfield (L, -7, LUA_SOURCE_TAGS);
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index 1fafbf0..b93260b 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -265,18 +265,18 @@ grl_util_add_table_to_media (lua_State *L,
     lua_gettable (L, -2);
     switch (type) {
     case G_TYPE_INT:
-      if (lua_isnumber (L, -1))
+      if (lua_isinteger (L, -1))
         grl_data_add_int (GRL_DATA (media), key_id, lua_tointeger (L, -1));
       break;
 
     case G_TYPE_INT64:
-      if (lua_isnumber (L, -1))
+      if (lua_isinteger (L, -1))
         grl_data_add_int64 (GRL_DATA (media), key_id, lua_tointeger (L, -1));
       break;
 
     case G_TYPE_FLOAT:
       if (lua_isnumber (L, -1))
-        grl_data_add_float (GRL_DATA (media), key_id, lua_tointeger (L, -1));
+        grl_data_add_float (GRL_DATA (media), key_id, lua_tonumber (L, -1));
       break;
 
     case G_TYPE_STRING:
@@ -348,7 +348,7 @@ grl_util_build_media (lua_State *L,
 
       switch (type) {
       case G_TYPE_INT:
-        if (lua_isnumber (L, -1)) {
+        if (lua_isinteger (L, -1)) {
           grl_data_set_int (GRL_DATA (media), key_id, lua_tointeger (L, -1));
         } else if (lua_istable (L, -1)) {
           grl_util_add_table_to_media (L, media, key_id, key_name, type);
@@ -370,7 +370,7 @@ grl_util_build_media (lua_State *L,
         break;
 
       case G_TYPE_INT64:
-        if (lua_isnumber (L, -1)) {
+        if (lua_isinteger (L, -1)) {
           grl_data_set_int64 (GRL_DATA (media), key_id, lua_tointeger (L, -1));
         } else if (lua_istable (L, -1)) {
           grl_util_add_table_to_media (L, media, key_id, key_name, type);
@@ -498,7 +498,7 @@ grl_util_fetch_done (GObject *source_object,
   } else {
     lua_newtable (L);
     for (i = 0; i < fo->num_urls; i++) {
-      lua_pushnumber (L, i + 1);
+      lua_pushinteger (L, i + 1);
       lua_pushlstring (L, fo->results[i], strlen (fo->results[i]));
       lua_settable (L, -3);
     }
@@ -635,7 +635,7 @@ grl_util_unzip_done (GObject *source_object,
 
   lua_newtable (L);
   for (i = 0; results[i] != NULL; i++) {
-    lua_pushnumber (L, i + 1);
+    lua_pushinteger (L, i + 1);
     lua_pushlstring (L, results[i], strlen (results[i]));
     lua_settable (L, -3);
   }
@@ -674,7 +674,7 @@ net_wc_new_with_options(lua_State *L,
 
       } else if (g_strcmp0 (key, "cache-size") == 0 ||
                  g_strcmp0 (key, "cache_size") == 0) {
-        guint size = lua_tonumber (L, -1);
+        guint size = lua_tointeger (L, -1);
         grl_net_wc_set_cache_size (wc, size);
 
       } else if (g_strcmp0 (key, "cache") == 0) {
@@ -682,11 +682,11 @@ net_wc_new_with_options(lua_State *L,
         grl_net_wc_set_cache (wc, use_cache);
 
       } else if (g_strcmp0 (key, "throttling") == 0) {
-        guint throttling = lua_tonumber (L, -1);
+        guint throttling = lua_tointeger (L, -1);
         grl_net_wc_set_throttling (wc, throttling);
 
       } else if (g_strcmp0 (key, "loglevel") == 0) {
-        guint level = lua_tonumber (L, -1);
+        guint level = lua_tointeger (L, -1);
         grl_net_wc_set_log_level (wc, level);
 
       } else {
@@ -746,21 +746,21 @@ grl_l_operation_get_options (lua_State *L)
   if (g_strcmp0 (option, "count") == 0) {
     gint count = grl_operation_options_get_count (os->options);
 
-    lua_pushnumber (L, count);
+    lua_pushinteger (L, count);
     return 1;
   }
 
   if (g_strcmp0 (option, "skip") == 0) {
     guint skip = grl_operation_options_get_skip (os->options);
 
-    lua_pushnumber (L, skip);
+    lua_pushinteger (L, skip);
     return 1;
   }
 
   if (g_strcmp0 (option, "flags") == 0) {
     GrlResolutionFlags flags = grl_operation_options_get_resolution_flags (os->options);
 
-    lua_pushnumber (L, (gint) flags);
+    lua_pushinteger (L, (gint) flags);
     return 1;
   }
 
@@ -777,7 +777,7 @@ grl_l_operation_get_options (lua_State *L)
     value = grl_operation_options_get_key_filter (os->options, key);
     switch (grl_registry_lookup_metadata_key_type (registry, key)) {
     case G_TYPE_INT:
-      (value) ? (void) lua_pushnumber (L, g_value_get_int (value)) : lua_pushnil (L);
+      (value) ? (void) lua_pushinteger (L, g_value_get_int (value)) : lua_pushnil (L);
       break;
 
     case G_TYPE_FLOAT:
@@ -814,8 +814,8 @@ grl_l_operation_get_options (lua_State *L)
       grl_operation_options_get_key_range_filter (os->options, key, &min, &max);
       switch (grl_registry_lookup_metadata_key_type (registry, key)) {
       case G_TYPE_INT:
-        (min) ? (void) lua_pushnumber (L, g_value_get_int (min)) : lua_pushnil (L);
-        (max) ? (void) lua_pushnumber (L, g_value_get_int (max)) : lua_pushnil (L);
+        (min) ? (void) lua_pushinteger (L, g_value_get_int (min)) : lua_pushnil (L);
+        (max) ? (void) lua_pushinteger (L, g_value_get_int (max)) : lua_pushnil (L);
         break;
 
       case G_TYPE_FLOAT:
@@ -837,7 +837,7 @@ grl_l_operation_get_options (lua_State *L)
   }
 
   if (g_strcmp0 (option, "operation-id") == 0) {
-    lua_pushnumber (L, (gint) os->operation_id);
+    lua_pushinteger (L, (gint) os->operation_id);
     return 1;
   }
 
@@ -937,7 +937,7 @@ grl_l_media_get_keys (lua_State *L)
       type = grl_registry_lookup_metadata_key_type (registry, key_id);
       switch (type) {
       case G_TYPE_INT:
-        lua_pushnumber (L, grl_data_get_int (GRL_DATA (os->media), key_id));
+        lua_pushinteger (L, grl_data_get_int (GRL_DATA (os->media), key_id));
         break;
       case G_TYPE_FLOAT:
         lua_pushnumber (L, grl_data_get_float (GRL_DATA (os->media), key_id));
@@ -946,7 +946,7 @@ grl_l_media_get_keys (lua_State *L)
         lua_pushstring (L, grl_data_get_string (GRL_DATA (os->media), key_id));
         break;
       case G_TYPE_INT64:
-        lua_pushnumber (L, grl_data_get_int64 (GRL_DATA (os->media), key_id));
+        lua_pushinteger (L, grl_data_get_int64 (GRL_DATA (os->media), key_id));
         break;
       case G_TYPE_BOOLEAN:
         lua_pushboolean (L, grl_data_get_boolean (GRL_DATA (os->media), key_id));
@@ -1063,7 +1063,7 @@ grl_l_fetch (lua_State *L)
 * grl.callback
 *
 * @media: (table) The media content to be returned.
-* @count: (number) Number of media remaining to the application.
+* @count: (integer) Number of media remaining to the application.
 * @return: Nothing;
 */
 static gint
@@ -1087,7 +1087,7 @@ grl_l_callback (lua_State *L)
   media = (os->op_type == LUA_RESOLVE) ? os->media : NULL;
   if (nparam > 0) {
     media = grl_util_build_media (L, media);
-    count = (lua_isnumber (L, 2)) ? lua_tonumber (L, 2) : 0;
+    count = (lua_isinteger (L, 2)) ? lua_tointeger (L, 2) : 0;
   }
 
   switch (os->op_type) {
diff --git a/src/lua-factory/lua-library/lua-json.c b/src/lua-factory/lua-library/lua-json.c
index c3f0640..1424c2e 100644
--- a/src/lua-factory/lua-library/lua-json.c
+++ b/src/lua-factory/lua-library/lua-json.c
@@ -79,7 +79,7 @@ build_table_from_json_reader (lua_State *L,
     lua_createtable (L, num_elements, 0);
     for (index_element = 0; index_element < num_elements; index_element++) {
       json_reader_read_element (reader, index_element);
-      lua_pushnumber (L, index_element + 1);
+      lua_pushinteger (L, index_element + 1);
       build_table_from_json_reader (L, reader);
       json_reader_end_element (reader);
     }
@@ -95,7 +95,7 @@ build_table_from_json_reader (lua_State *L,
         lua_pushstring (L, json_reader_get_string_value (reader));
         break;
       case G_TYPE_INT64:
-        lua_pushnumber (L, json_reader_get_int_value (reader));
+        lua_pushinteger (L, json_reader_get_int_value (reader));
         break;
       case G_TYPE_DOUBLE:
         lua_pushnumber (L, json_reader_get_double_value (reader));


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