this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use debug.traceback for stack traces in Lua-based carts. (#2705)

Fennel carts have debug.traceback set to fennel.traceback during
initialization, which is a function that uses sourcemaps to convert
the traceback data which Lua knows about (with line numbers based on
the Lua output from the Fennel compiler) into traceback data based on
line numbers in the original source code.

Previously this had no effect because debug.traceback was never
actually run; luaapi.c contained a call to the underlying
luaL_traceback function instead, which did not know about
sourcemaps. Replacing it with a call to debug.traceback allows
us to see stack traces that use sourcemap data.

This change should have no effect on Lua carts; only Fennel carts and
perhaps Moonscript carts.

Also in this patch we set the filename field when compiling Fennel
carts; without this the custom fennel.traceback function can't use
sourcemaps as needed.

authored by

Phil Hagelberg and committed by
GitHub
8e19cb63 3125d4a4

+9 -2
+2 -1
src/api/fennel.c
··· 31 31 io = { read = true } 32 32 local fennel = require("fennel") 33 33 debug.traceback = fennel.traceback 34 - local opts = {allowedGlobals = false, ["error-pinpoint"]={">>", "<<"}} 34 + local opts = {allowedGlobals = false, ["error-pinpoint"]={">>", "<<"}, 35 + filename="game.fnl"} 35 36 local src = ... 36 37 if(src:find("\n;; +strict: *true")) then opts.allowedGlobals = nil end 37 38 local ok, msg = pcall(fennel.eval, src, opts)
+7 -1
src/api/luaapi.c
··· 1676 1676 else 1677 1677 msg = lua_pushfstring(lua, "(error object is a %s value)", luaL_typename(lua, 1)); 1678 1678 } 1679 - luaL_traceback(lua, lua, msg, 1); /* append a standard traceback */ 1679 + /* call the debug.traceback function instead of luaL_traceback so */ 1680 + /* customized sourcemap-aware debug.traceback can give better line numbers */ 1681 + lua_getglobal(lua, "debug"); 1682 + lua_pushstring(lua, "traceback"); 1683 + lua_gettable(lua, -2); 1684 + lua_pushstring(lua, msg); 1685 + lua_call(lua, 1, 1); 1680 1686 return 1; /* return the traceback */ 1681 1687 } 1682 1688