From 097d9a2834b7dbceb44b24f3ff73d798b98900f7 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 4 May 2017 12:12:20 +1000 Subject: tests/manual-tests/lua-cli.js: Add msghandler to get tracebacks --- tests/manual-tests/lua-cli.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/manual-tests/lua-cli.js b/tests/manual-tests/lua-cli.js index b450b40..5e47b93 100755 --- a/tests/manual-tests/lua-cli.js +++ b/tests/manual-tests/lua-cli.js @@ -17,8 +17,25 @@ const report = function(L, status) { return status; }; +const msghandler = function(L) { + let msg = lua.lua_tostring(L, 1); + if (msg === null) { /* is error object not a string? */ + if (lauxlib.luaL_callmeta(L, 1, "__tostring") && /* does it have a metamethod */ + lua.lua_type(L, -1) == lua.LUA_TSTRING) /* that produces a string? */ + return 1; /* that is the message */ + else + msg = lua.lua_pushstring(L, lua.to_luastring(`(error object is a ${lua.to_jsstring(lauxlib.luaL_typename(L, 1))} value)`)); + } + lauxlib.luaL_traceback(L, L, msg, 1); /* append a standard traceback */ + return 1; /* return the traceback */ +}; + const docall = function(L, narg, nres) { - let status = lua.lua_pcall(L, narg, nres, 0); + let base = lua.lua_gettop(L) - narg; + lua.lua_pushcfunction(L, msghandler); + lua.lua_insert(L, base); + let status = lua.lua_pcall(L, narg, nres, base); + lua.lua_remove(L, base); return status; }; -- cgit v1.2.3-70-g09d2