From 23d15010edc905a3b7c123e85ef6d1960d3da039 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Tue, 21 Feb 2017 08:46:48 +0100 Subject: luaG_ functions --- src/lauxlib.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/lauxlib.js') diff --git a/src/lauxlib.js b/src/lauxlib.js index 16b480d..b879446 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -17,6 +17,26 @@ const panic = function(L) { throw new Error(msg); }; +// const luaL_argerror = function(L, arg, extramsg) { +// let ar = new lua.lua_Debug(); +// +// if (!lapi.lua_getstack(L, 0, ar)) /* no stack frame? */ +// return luaL_error(L, 'bad argument #%d (%s)', arg, extramsg); +// +// ldebug.lua_getinfo(L, 'n', ar); +// +// if (ar.namewhat === 'method') { +// arg--; /* do not count 'self' */ +// if (arg === 0) /* error is in the self argument itself? */ +// return luaL_error(L, "calling '%s' on bad self (%s)", ar.name, extramsg); +// } +// +// if (ar.name === null) +// ar.name = pushglobalfuncname(L, ar) ? lapi.lua_tostring(L, -1) : "?"; +// +// return luaL_error(L, "bad argument #%d to '%s' (%s)", arg, ar.name, extramsg); +// }; + const typeerror = function(L, arg, tname) { let typearg; if (luaL_getmetafield(L, arg, "__name") === CT.LUA_TSTRING) @@ -45,6 +65,17 @@ const luaL_where = function(L, level) { lapi.lua_pushstring(L, ""); }; +const luaL_error = function(L, fmt, ...args) { + let i = 0; + + // TODO: bypassing lua_pushvstring for now + lapi.lua_pushstring(L, fmt.replace(/(^%[sfIpdcU]|([^%])%[sfIpdcU])/g, function (m, p1, p2, off) { + return p2 ? p2 + args[i++] : args[i++]; + })); + + return lapi.lua_error(L); +}; + const tag_error = function(L, arg, tag) { typeerror(L, arg, lapi.lua_typename(L, tag)); }; @@ -252,4 +283,5 @@ module.exports.luaL_optstring = luaL_optstring; module.exports.luaL_checkinteger = luaL_checkinteger; module.exports.luaL_optinteger = luaL_optinteger; module.exports.luaL_opt = luaL_opt; -module.exports.luaL_where = luaL_where; \ No newline at end of file +module.exports.luaL_where = luaL_where; +module.exports.luaL_error = luaL_error; \ No newline at end of file -- cgit v1.2.3-54-g00ecf