-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfancyerror.lua
More file actions
121 lines (91 loc) · 3.1 KB
/
fancyerror.lua
File metadata and controls
121 lines (91 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
local utf8 = require("utf8")
-- ==========================================================[ DEBUG FUNCTIONS ]==============================================================--
debugs = {}
function error_printer(msg, layer)
print((debug.traceback("Error: " .. tostring(msg), 1+(layer or 1)):gsub("\n[^\n]+$", "")))
end
function love.errorhandler(msg)
msg = tostring(msg)
error_printer(msg, 2)
if not love.window or not love.graphics or not love.event then
return
end
if not love.graphics.isCreated() or not love.window.isOpen() then
local success, status = pcall(love.window.setMode, 800, 600)
if not success or not status then
return
end
end
if love.mouse then
love.mouse.setVisible(true)
love.mouse.setGrabbed(false)
love.mouse.setRelativeMode(false)
if love.mouse.isCursorSupported() then
love.mouse.setCursor()
end
end
if love.audio then love.audio.stop() end
love.graphics.reset()
local font = love.graphics.setNewFont(16)
love.graphics.setColor(246/255, 246/255, 246/255)
local trace = debug.traceback()
love.graphics.origin()
local sanitizedmsg = {}
for char in msg:gmatch(utf8.charpattern) do
table.insert(sanitizedmsg, char)
end
sanitizedmsg = table.concat(sanitizedmsg)
local err = {}
table.insert(err, "Error\n")
table.insert(err, sanitizedmsg)
if #sanitizedmsg ~= #msg then
table.insert(err, "Invalid UTF-8 string in error message.")
end
table.insert(err, "\n")
for l in trace:gmatch("(.-)\n") do
if not l:match("boot.lua") then
l = l:gsub("stack traceback:", "Traceback\n")
table.insert(err, l)
end
end
local p = ""
for i = 3, #err, 1 do p = p..err[i].."\n" end
p = p:gsub("\t", "")
p = p:gsub("%[string \"(.-)\"%]", "%1")
local debugslen = 0
for key, value in pairs(debugs) do
debugslen = debugslen + 1
end
success = love.window.setMode(800, 600, {resizable=true, vsync=true, minwidth=400, minheight=300})
local function draw()
if not love.graphics.isActive() then return end
local pos, width = 70, love.graphics.getWidth()
love.graphics.clear(30/255, 30/255, 30/255)
love.graphics.setColor(248/255, 46/255, 105/255)
love.graphics.printf(err[1], pos, pos, width - pos)
love.graphics.setColor(225/255, 157/255, 40/255)
love.graphics.printf(err[2], pos, pos+40, width - pos)
love.graphics.setColor(166/255, 226/255, 41/255)
love.graphics.printf(p, pos, pos*2, width - pos)
if debugslen > 0 then
love.graphics.setColor(225/255, 157/255, 40/255)
love.graphics.print("Debug Variables:", width/2, pos)
love.graphics.setColor(166/255, 226/255, 41/255)
local i = 0
for k,v in pairs(debugs) do
love.graphics.printf(("%s = %s"):format(k,tostring(v)), width/2, pos*2 + (pos*i)/2, width - pos)
i = i + 1
end
end
love.graphics.present()
end
return function()
love.event.pump()
for e, a, b, c in love.event.poll() do
if e == "quit" then return 1
elseif e == "keypressed" and a == "escape" then return 1 end
end
draw()
if love.timer then love.timer.sleep(0.1) end
end
end