From 7236b4bf648ba2fffc83d0b031766208a183e52b Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 13 Feb 2017 11:39:43 +0100 Subject: l_isfalse as TValue method --- src/lobject.js | 4 ++++ src/ltm.js | 2 +- src/lvm.js | 13 ++++--------- tests/lvm.js | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lobject.js b/src/lobject.js index 7b39668..385ac9c 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -102,6 +102,10 @@ class TValue { return this.checktag(CT.LUA_TDEADKEY); } + l_isfalse() { + return this.ttisnil() || (this.ttisboolean() && this.value === false); + } + } const nil = new TValue(CT.LUA_TNIL, null); diff --git a/src/ltm.js b/src/ltm.js index e08c511..041e233 100644 --- a/src/ltm.js +++ b/src/ltm.js @@ -79,7 +79,7 @@ const luaT_callorderTM = function(L, p1, p2, event) { if (!luaT_callbinTM(L, p2, p2, L.top, event)) return -1; else - return !l_isfalse(L.stack[L.top]) ? 1 : 0; + return !L.stack[L.top].l_isfalse() ? 1 : 0; }; const luaT_gettmbyobj = function(L, o, event) { diff --git a/src/lvm.js b/src/lvm.js index 7be6b01..8d6f5c7 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -372,7 +372,7 @@ const luaV_execute = function(L) { } case "OP_NOT": { let op = L.stack[RB(L, base, i)]; - L.stack[ra] = new TValue(CT.LUA_TBOOLEAN, l_isfalse(op)); + L.stack[ra] = new TValue(CT.LUA_TBOOLEAN, op.l_isfalse()); break; } case "OP_LEN": { @@ -412,7 +412,7 @@ const luaV_execute = function(L) { break; } case "OP_TEST": { - if (i.C ? l_isfalse(L.stack[ra]) : !l_isfalse(L.stack[ra])) + if (i.C ? L.stack[ra].l_isfalse() : !L.stack[ra].l_isfalse()) ci.pcOff++; else donextjump(L, ci); @@ -420,7 +420,7 @@ const luaV_execute = function(L) { } case "OP_TESTSET": { let rb = L.stack[RB(L, base, i)]; - if (i.C ? l_isfalse(rb) : !l_isfalse(rb)) + if (i.C ? rb.l_isfalse() : !rb.l_isfalse()) ci.pcOff++; else { L.stack[ra] = rb; @@ -731,7 +731,7 @@ const luaV_equalobj = function(L, t1, t2) { return 0; ltm.luaT_callTM(L, tm, t1, t2, L.top, 1); - return !l_isfalse(L.stack[L.top]); + return !L.stack[L.top].l_isfalse(); }; const forlimit = function(obj, step) { @@ -846,10 +846,6 @@ const l_strcmp = function(ls, rs) { return ls.value === rs.value ? 0 : (ls.value < rs.value ? -1 : 1); }; -const l_isfalse = function(o) { - return o.ttisnil() || (o.ttisboolean() && o.value === false); -}; - /* ** Main operation 'ra' = #rb'. */ @@ -942,7 +938,6 @@ module.exports = { LEintfloat: LEintfloat, LTintfloat: LTintfloat, l_strcmp: l_strcmp, - l_isfalse: l_isfalse, luaV_objlen: luaV_objlen, stackerror: stackerror, luaD_call: luaD_call, diff --git a/tests/lvm.js b/tests/lvm.js index 5de8b31..d11eb9d 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -747,7 +747,7 @@ test('LEN', function (t) { return #t, #t2, #s `, L; - t.plan(3); + t.plan(4); t.comment("Running following code: \n" + luaCode); -- cgit v1.2.3-70-g09d2