summaryrefslogtreecommitdiff
path: root/package/utils/lua
diff options
context:
space:
mode:
authorDavid Thornley <david.thornley@touchstargroup.com>2016-05-11 13:28:53 +1000
committerJo-Philipp Wich <jo@mein.io>2016-05-13 17:03:53 +0200
commitda0226fa7eece0b87bcc04d79bd1a9b198d09fd0 (patch)
treea5eba82f18841740e3fe480891fd7230656f4522 /package/utils/lua
parent45e0f8b82645faaeea35256c1def0f7706b495ba (diff)
downloadmtk-20170518-da0226fa7eece0b87bcc04d79bd1a9b198d09fd0.zip
mtk-20170518-da0226fa7eece0b87bcc04d79bd1a9b198d09fd0.tar.gz
mtk-20170518-da0226fa7eece0b87bcc04d79bd1a9b198d09fd0.tar.bz2
lua: Fixed broken __lt/__le operators caused by lnum patch.
This was found while investigating why luarocks does not work. It was traced to a quite old lnum patch for 5.1.3. I compared against the latest 5.1.4 patch - https://github.com/LuaDist/lualnum and discovered the lessthan/lessequal evaluation was not falling through to the call_orderTM (tag methods). I have tested LuCI (simple tests) and used the following lua code to validate the patch (both host and target patches supplied): - > local my_mt = { > __eq = function(v1, v2) > print("__eq") > return false > end, > __lt = function(v1, v2) > print("__lt") > return false > end, > __le = function(v1, v2) > print("__le") > return false > end > } > > function get_my(vstring) > local my = {} > my.string = vstring; > setmetatable(my, my_mt); > return my; > end > > local a = get_my("1.0") > local b = get_my("1.0") > > local eq_works = a == b; > local lt_works = a < b; > local gt_works = a > b; > > local lte_works = a <= b; > local gte_works = a >= b; Without the patch the following error will be presented: - “attempt to compare two table values” Signed-off-by: David Thornley <david.thornley@touchstargroup.com>
Diffstat (limited to 'package/utils/lua')
-rw-r--r--package/utils/lua/patches-host/012-lnum-fix-ltle-relational-operators.patch22
-rw-r--r--package/utils/lua/patches/012-lnum-fix-ltle-relational-operators.patch22
2 files changed, 44 insertions, 0 deletions
diff --git a/package/utils/lua/patches-host/012-lnum-fix-ltle-relational-operators.patch b/package/utils/lua/patches-host/012-lnum-fix-ltle-relational-operators.patch
new file mode 100644
index 0000000..937fc13
--- /dev/null
+++ b/package/utils/lua/patches-host/012-lnum-fix-ltle-relational-operators.patch
@@ -0,0 +1,22 @@
+--- a/src/lvm.c
++++ b/src/lvm.c
+@@ -284,7 +284,8 @@ int luaV_lessthan (lua_State *L, const T
+ else
+ return luai_numlt( nvalue_fast(l), cast_num(ivalue(r)) );
+
+- } else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
++ }
++ if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
+ return res;
+
+ return luaG_ordererror(L, l, r);
+@@ -322,7 +323,8 @@ static int lessequal (lua_State *L, cons
+ else
+ return luai_numle( nvalue_fast(l), cast_num(ivalue(r)) );
+
+- } else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
++ }
++ if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
+ return res;
+ else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
+ return !res;
diff --git a/package/utils/lua/patches/012-lnum-fix-ltle-relational-operators.patch b/package/utils/lua/patches/012-lnum-fix-ltle-relational-operators.patch
new file mode 100644
index 0000000..937fc13
--- /dev/null
+++ b/package/utils/lua/patches/012-lnum-fix-ltle-relational-operators.patch
@@ -0,0 +1,22 @@
+--- a/src/lvm.c
++++ b/src/lvm.c
+@@ -284,7 +284,8 @@ int luaV_lessthan (lua_State *L, const T
+ else
+ return luai_numlt( nvalue_fast(l), cast_num(ivalue(r)) );
+
+- } else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
++ }
++ if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
+ return res;
+
+ return luaG_ordererror(L, l, r);
+@@ -322,7 +323,8 @@ static int lessequal (lua_State *L, cons
+ else
+ return luai_numle( nvalue_fast(l), cast_num(ivalue(r)) );
+
+- } else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
++ }
++ if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
+ return res;
+ else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
+ return !res;