Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function run(mainFunc, errFunc)
- if type(mainFunc) ~= "function" then
- error("Nothing to run", 2)
- end
- local oldOsShutdown, oldCoroutineStatus = os.shutdown, coroutine.status
- local function clearScreen()
- term.redirect(type(term.native) == "function" and term.native() or term.native)
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.white)
- term.setCursorPos(1, 1)
- term.setCursorBlink(false)
- term.clear()
- end
- local function coroutineStatusOverride(...)
- return "dead"
- end
- local function osShutdownOverride()
- clearScreen()
- rednet.close()
- os.unloadAPI("rednet")
- os.loadAPI("/rom/apis/rednet")
- rawset(os, "shutdown", oldOsShutdown)
- rawset(coroutine, "status", oldCoroutineStatus)
- local ok, err = pcall(mainFunc)
- if not ok then
- clearScreen()
- pcall( function()
- if type(errFunc) == "function" then
- errFunc(err)
- else
- printError(err)
- print("Press any key to continue")
- os.pullEvent("key")
- end
- end )
- end
- os.shutdown()
- end
- rawset(os, "shutdown", osShutdownOverride)
- rawset(coroutine, "status", coroutineStatusOverride)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement