[grilo-plugins] lua-factory: Accept strings representing integers as integers
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] lua-factory: Accept strings representing integers as integers
- Date: Wed, 23 Sep 2015 13:26:20 +0000 (UTC)
commit 1e20497737db94c0932a12b4395859b4da451aaa
Author: George Sedov <radist morse gmail com>
Date: Mon Sep 7 13:20:24 2015 +0300
lua-factory: Accept strings representing integers as integers
This is a regression from Lua 5.2, lua_isinteger() does not convert from
strings to integer like lua_isnumber() used to.
https://bugzilla.gnome.org/show_bug.cgi?id=753141
src/lua-factory/grl-lua-library.c | 34 +++++++++++++++-------------------
1 files changed, 15 insertions(+), 19 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index ed7130d..2db849e 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -265,13 +265,13 @@ grl_util_add_table_to_media (lua_State *L,
lua_gettable (L, -2);
switch (type) {
case G_TYPE_INT:
- 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_isinteger (L, -1))
- grl_data_add_int64 (GRL_DATA (media), key_id, lua_tointeger (L, -1));
+ if (lua_isnumber (L, -1)) {
+ gint success;
+ gint value = lua_tointegerx (L, -1, &success);
+ if (success)
+ grl_data_add_int (GRL_DATA (media), key_id, value);
+ }
break;
case G_TYPE_FLOAT:
@@ -348,8 +348,15 @@ grl_util_build_media (lua_State *L,
switch (type) {
case G_TYPE_INT:
- if (lua_isinteger (L, -1)) {
- grl_data_set_int (GRL_DATA (media), key_id, lua_tointeger (L, -1));
+ case G_TYPE_INT64:
+ if (lua_isnumber (L, -1)) {
+ gint success;
+ gint value = lua_tointegerx (L, -1, &success);
+ if (success)
+ grl_data_set_int (GRL_DATA (media), key_id, value);
+ else
+ GRL_WARNING ("'%s' requires an INT type, while a value '%s' was provided",
+ key_name, lua_tostring(L, -1));
} else if (lua_istable (L, -1)) {
grl_util_add_table_to_media (L, media, key_id, key_name, type);
} else if (!lua_isnil (L, -1)) {
@@ -369,17 +376,6 @@ grl_util_build_media (lua_State *L,
}
break;
- case G_TYPE_INT64:
- 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);
- } else if (!lua_isnil (L, -1)) {
- GRL_WARNING ("'%s' is not compatible for '%s'",
- lua_typename (L, -1), key_name);
- }
- break;
-
case G_TYPE_STRING:
if (lua_isstring (L, -1)) {
grl_data_set_lua_string (GRL_DATA (media), key_id, key_name, lua_tostring (L, -1));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]