Simplifying the error callback
Since the code of the error callback will probably be read and edited by lovers, perhaps it could be good to make the code as simple as it can be.
I've kind of had a go at doing this, and uh, it's not perfect, or rigorously tested, or exactly the same as it was. I don't think setting the
debug.traceback level to 2 affected anything when in
boot.lua (I could certainly be mistaken), but it seemed to make the error message make more sense when
love.errhand was in
main.lua, so it could be useful to have for copy-and-pasting purposes if it doesn't change anything else.
function love.errhand(msg) msg = tostring(msg) local trace = "" for l in string.gmatch(debug.traceback("", 2), "(.-)\n") do if not string.match(l, "boot.lua") and l ~= "stack traceback:" and l ~= "" then trace = trace..l.."\n" end end trace = string.gsub(trace, "\n$", "") print("Error: "..msg.."\nTraceback:\n"..trace) if not love.window or not love.graphics or not love.event then return end if not love.graphics.isCreated() or not love.window.isCreated() then if not pcall(love.window.setMode, 800, 600) then return end end if love.audio then love.audio.stop() end love.graphics.reset() love.graphics.origin() love.graphics.setBackgroundColor(255, 157, 255) love.graphics.setNewFont(14) local output = "Error\n\n"..msg.."\n\n\n"..trace while true do love.event.pump() for e, a, b, c in love.event.poll() do if e == "quit" then return end if e == "keypressed" and a == "escape" then return end end love.graphics.clear() love.graphics.printf(output, 70, 70, love.graphics.getWidth() - 70) love.graphics.present() if love.timer then love.timer.sleep(0.1) end end end