-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_handler.lua2p
168 lines (127 loc) · 3.39 KB
/
error_handler.lua2p
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
local Lily = require("modules.lily.lily")
local UTF8 = require("utf8")
local ErrorHandler = {}
local font, p
local pos_x, pos_y = 0, 24
local function error_printer(msg, layer)
local err_msg = (debug.traceback("Error: " .. tostring(msg),
1 + (layer or 1)):gsub("\n[^\n]+$", ""))
print(err_msg)
end
local function draw()
--TODO improve this
love.graphics.clear()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(p, pos_x, pos_y, love.graphics.getWidth(), "center")
love.graphics.present()
end
local function copy_to_clipboard(arg)
if not love.system then
return
end
love.system.setClipboardText(arg)
p = p .. "\nCopied to clipboard"
draw()
end
function ErrorHandler.callback(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.joystick then
for i, v in ipairs(love.joystick.getJoysticks()) do
v:setVibration()
end
end
if love.audio then
love.audio.stop()
end
love.graphics.reset()
font = love.graphics.newFont("res/fonts/DigitalDisco.ttf", 16)
font:setFilter($_FONT_FILTER, $_FONT_FILTER)
love.graphics.setFont(font)
love.graphics.setColor(1, 1, 1, 1)
local trace = debug.traceback()
love.graphics.origin()
local sanitized_msg = {}
for char in msg:gmatch(UTF8.charpattern) do
table.insert(sanitized_msg, char)
end
sanitized_msg = table.concat(sanitized_msg)
local err = {}
table.insert(err, "SORRY! SOMETHING UNEXPECTED OCCURED!")
table.insert(err, "The developer will work hard to fix this, please have patience")
table.insert(err, "You can help by submitting the error throught GitHub or Itch.io")
table.insert(err, "Thank you!\n")
!if _DEV then
table.insert(err, sanitized_msg)
if #sanitized_msg ~= #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
!end
p = table.concat(err, "\n")
p = p:gsub("\t", "")
p = p:gsub("$[string \"(.-)\"%]", "%1")
local text_full = p
Lily.quit()
return function()
love.event.pump()
for e, a, b, c in love.event.poll() do
if e == "quit" then
return 1
!if _PLATFORM == "desktop" then
elseif e == "keypressed" and a == "escaped" then
return 1
elseif e == "keypressed" and a == "c" and
love.keyboard.isDown("lctrl", "rctrl") then
copy_to_clipboard(text_full)
end
!else
if e == "touchpressed" then
local name = love.window.getTitle()
if #name == 0 or name == "Untitled" then
name = "Game"
end
local buttons = {"OK", "Cancel"}
if love.system then
buttons[3] = "Copy to clipboard"
end
local pressed = love.window.showMessageBox("Quit " .. name .. "?",
"", buttons)
if presssed == 1 then
return 1
elseif pressed == 3 then
copy_to_clipboard(text_full)
end
end
!end
end
draw()
if love.timer then
love.timer.sleep(0.1)
end
end
end
return ErrorHandler