From fc911817a8401d0696407e91501f0ef65f05b711 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 22 Feb 2017 17:32:28 +0100 Subject: use luaL_argerror/error instead of throwing --- src/lbaselib.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/lbaselib.js') diff --git a/src/lbaselib.js b/src/lbaselib.js index 2eacaaf..f405a7d 100644 --- a/src/lbaselib.js +++ b/src/lbaselib.js @@ -110,6 +110,17 @@ const pairsmeta = function(L, method, iszero, iter) { return 3; }; +const luaB_next = function(L) { + lauxlib.luaL_checktype(L, 1, CT.LUA_TTABLE); + lapi.lua_settop(L, 2); /* create a 2nd argument if there isn't one */ + if (lapi.lua_next(L, 1)) + return 2; + else { + lapi.lua_pushnil(L); + return 1; + } +}; + /* ** Traversal function for 'ipairs' */ @@ -244,6 +255,7 @@ const base_funcs = { "tostring": luaB_tostring, "tonumber": luaB_tonumber, "getmetatable": luaB_getmetatable, + "next": luaB_next, "ipairs": luaB_ipairs, "select": luaB_select, "setmetatable": luaB_setmetatable, -- cgit v1.2.3-54-g00ecf