From 7b7775f9edd1fd68bb4f6ec975fc08985e898816 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 21 May 2017 20:44:31 +1000 Subject: lua_numbertointeger should return false on failure Found via behaviour of pushnumint in lmathlib --- src/luaconf.js | 2 +- src/lvm.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/luaconf.js b/src/luaconf.js index 7cf3d06..3d0d18f 100644 --- a/src/luaconf.js +++ b/src/luaconf.js @@ -19,7 +19,7 @@ const LUAI_MAXSTACK = 1000000; const LUA_IDSIZE = 60; const lua_numbertointeger = function(n) { - return n >= llimit.MIN_INT && n < -llimit.MIN_INT ? n : 0; + return n >= llimit.MIN_INT && n < -llimit.MIN_INT ? n : false; }; const LUA_INTEGER_FRMLEN = ""; diff --git a/src/lvm.js b/src/lvm.js index dfb2ed5..3cf406a 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -801,8 +801,7 @@ const luaV_tointeger = function(obj, mode) { f += 1; /* convert floor to ceil (remember: n !== f) */ } - let res = luaconf.lua_numbertointeger(f); - return res !== 0 ? res : (n === 0 ? 0 : false); + return luaconf.lua_numbertointeger(f); } else if (obj.ttisinteger()) { return obj.value; } else if (obj.ttisstring()) { -- cgit v1.2.3-70-g09d2