Skip to content

Instantly share code, notes, and snippets.

@Fingercomp

Fingercomp/crash.lua

Created Dec 11, 2016
Embed
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment