diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-04 12:12:20 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-04 12:12:20 +1000 |
commit | 097d9a2834b7dbceb44b24f3ff73d798b98900f7 (patch) | |
tree | f24a664db3457b170de494703204b6fcc2d1b266 /tests | |
parent | 7464d7ea0f84960710cf458c83b0bec4a549b3f5 (diff) | |
download | fengari-097d9a2834b7dbceb44b24f3ff73d798b98900f7.tar.gz fengari-097d9a2834b7dbceb44b24f3ff73d798b98900f7.tar.bz2 fengari-097d9a2834b7dbceb44b24f3ff73d798b98900f7.zip |
tests/manual-tests/lua-cli.js: Add msghandler to get tracebacks
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/manual-tests/lua-cli.js | 19 |
1 files changed, 18 insertions, 1 deletions
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; }; |