From b482e19917395c842780bd2b8da7731158947c40 Mon Sep 17 00:00:00 2001 From: denis Date: Thu, 7 Sep 2017 03:44:37 +0300 Subject: src/lapi.js, src/lauxlib.js: lua_tointeger should return 0 when conversion fails for luaL_ref to work --- src/lapi.js | 11 ++++++----- src/lauxlib.js | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index b7fed83..1be0837 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -708,11 +708,16 @@ const lua_tocfunction = function(L, idx) { }; const lua_tointeger = function(L, idx) { + let n = lua_tointegerx(L, idx); + return n === false ? 0 : n; +}; + +const lua_tointegerx = function(L, idx) { return lvm.tointeger(index2addr(L, idx)); }; const lua_tonumber = function(L, idx) { - let n = lvm.tonumber(index2addr(L, idx)); + let n = lua_tonumberx(L, idx); return n === false ? 0 : n; }; @@ -814,10 +819,6 @@ const lua_stringtonumber = function(L, s) { return 0; }; -const lua_tointegerx = function(L, idx) { - return lvm.tointeger(index2addr(L, idx)); -}; - const f_call = function(L, ud) { ldo.luaD_callnoyield(L, ud.funcOff, ud.nresults); }; diff --git a/src/lauxlib.js b/src/lauxlib.js index b551d4f..ab8a8a0 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -343,7 +343,7 @@ const luaL_optnumber = function(L, arg, def) { }; const luaL_checkinteger = function(L, arg) { - let d = lua.lua_tointeger(L, arg); + let d = lua.lua_tointegerx(L, arg); if (d === false) interror(L, arg); return d; -- cgit v1.2.3-54-g00ecf