From 03fa39649de945d5a392f460fd592f815534f69a Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Sun, 28 May 2017 11:54:09 +0200 Subject: lua_tonumberx lua_tonumber should return 0 if argument is not convertible to a number. But luaL_checknumber uses lua_tonumberx and tests isnum. -> lua_tonumberx return false if argument is not convertible to a number. --- src/lapi.js | 5 +++++ src/lauxlib.js | 2 +- src/lua.js | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index 1dfd112..90533f7 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -720,6 +720,10 @@ const lua_tonumber = function(L, idx) { return n === false ? 0 : n; }; +const lua_tonumberx = function(L, idx) { + return lvm.tonumber(index2addr(L, idx)); +}; + const lua_touserdata = function(L, idx) { let o = index2addr(L, idx); switch (o.ttnov()) { @@ -1224,6 +1228,7 @@ module.exports.lua_tojsstring = lua_tojsstring; module.exports.lua_toljsstring = lua_toljsstring; module.exports.lua_tolstring = lua_tolstring; module.exports.lua_tonumber = lua_tonumber; +module.exports.lua_tonumberx = lua_tonumberx; module.exports.lua_topointer = lua_topointer; module.exports.lua_toproxy = lua_toproxy; module.exports.lua_tostring = lua_tostring; diff --git a/src/lauxlib.js b/src/lauxlib.js index 0672c14..3851ee7 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -333,7 +333,7 @@ const interror = function(L, arg) { }; const luaL_checknumber = function(L, arg) { - let d = lua.lua_tonumber(L, arg); + let d = lua.lua_tonumberx(L, arg); if (d === false) tag_error(L, arg, lua.LUA_TNUMBER); return d; diff --git a/src/lua.js b/src/lua.js index c921982..07edaf1 100644 --- a/src/lua.js +++ b/src/lua.js @@ -200,6 +200,7 @@ module.exports.lua_tojsstring = lapi.lua_tojsstring; module.exports.lua_toljsstring = lapi.lua_toljsstring; module.exports.lua_tolstring = lapi.lua_tolstring; module.exports.lua_tonumber = lapi.lua_tonumber; +module.exports.lua_tonumberx = lapi.lua_tonumberx; module.exports.lua_topointer = lapi.lua_topointer; module.exports.lua_toproxy = lapi.lua_toproxy; module.exports.lua_tostring = lapi.lua_tostring; -- cgit v1.2.3-70-g09d2