From 63446e402d2aa70bb53cbc40563edafb6383cf5d Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 26 May 2017 15:54:47 +1000 Subject: Have ltm.luaT_callorderTM return a boolean --- src/ltm.js | 6 +++--- src/lvm.js | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ltm.js b/src/ltm.js index 8f4908c..88f25fb 100644 --- a/src/ltm.js +++ b/src/ltm.js @@ -159,11 +159,11 @@ const luaT_trybinTM = function(L, p1, p2, res, event) { }; const luaT_callorderTM = function(L, p1, p2, event) { - let res = new lobject.TValue(CT.LUA_TNIL, null); + let res = new lobject.TValue(); if (!luaT_callbinTM(L, p1, p2, res, event)) - return -1; + return null; else - return res.l_isfalse() ? 0 : 1; + return !res.l_isfalse(); }; const fasttm = function(l, et, e) { diff --git a/src/lvm.js b/src/lvm.js index 724f689..9bbe768 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -752,31 +752,29 @@ const luaV_lessthan = function(L, l, r) { return l_strcmp(l.tsvalue(), r.tsvalue()) < 0 ? 1 : 0; else { let res = ltm.luaT_callorderTM(L, l, r, ltm.TMS.TM_LT); - if (res < 0) + if (res === null) ldebug.luaG_ordererror(L, l, r); return res ? 1 : 0; } }; const luaV_lessequal = function(L, l, r) { - let res; - if (l.ttisnumber() && r.ttisnumber()) return LEnum(l, r) ? 1 : 0; else if (l.ttisstring() && r.ttisstring()) return l_strcmp(l.tsvalue(), r.tsvalue()) <= 0 ? 1 : 0; else { - res = ltm.luaT_callorderTM(L, l, r, ltm.TMS.TM_LE); - if (res >= 0) + let res = ltm.luaT_callorderTM(L, l, r, ltm.TMS.TM_LE); + if (res !== null) return res ? 1 : 0; } /* try 'lt': */ L.ci.callstatus |= lstate.CIST_LEQ; /* mark it is doing 'lt' for 'le' */ - res = ltm.luaT_callorderTM(L, r, l, ltm.TMS.TM_LT); + let res = ltm.luaT_callorderTM(L, r, l, ltm.TMS.TM_LT); L.ci.callstatus ^= lstate.CIST_LEQ; /* clear mark */ - if (res < 0) + if (res === null) ldebug.luaG_ordererror(L, l, r); - return res !== 1 ? 1 : 0; /* result is negated */ + return res ? 0 : 1; /* result is negated */ }; const luaV_equalobj = function(L, t1, t2) { -- cgit v1.2.3-70-g09d2