-
Notifications
You must be signed in to change notification settings - Fork 0
/
crash.lua
34 lines (28 loc) · 837 Bytes
/
crash.lua
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
local shell = require("shell")
local fs = require("filesystem")
local args = {...}
local elog = shell.resolve(table.remove(args, 1))
local path = shell.resolve(table.remove(args, 1))
if not elog or not path then
print("USAGE: crash <error log path> <path to program> [arguments...]")
return 1
end
if not fs.exists(path) or fs.isDirectory(path) then
print("Invalid path.")
print("USAGE: crash <error log path> <path to program> [arguments...]")
return 1
end
if not fs.exists(fs.path(elog)) then
fs.makeDirectory(fs.path(elog))
end
local result = {xpcall(loadfile(path), debug.traceback, table.unpack(args))}
if result[1] then
return table.unpack(result, 2)
else
print("Program crashed.")
local file = io.open(elog, "w")
file:write(result[2])
file:close()
print("Error log saved to: " .. elog)
return 0
end