Advertisement
blunty666

override

Aug 30th, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. local function run(mainFunc, errFunc)
  2.     if type(mainFunc) ~= "function" then
  3.         error("Nothing to run", 2)
  4.     end
  5.  
  6.     local oldOsShutdown, oldCoroutineStatus = os.shutdown, coroutine.status
  7.  
  8.     local function clearScreen()
  9.         term.redirect(type(term.native) == "function" and term.native() or term.native)
  10.         term.setBackgroundColour(colours.black)
  11.         term.setTextColour(colours.white)
  12.         term.setCursorPos(1, 1)
  13.         term.setCursorBlink(false)
  14.         term.clear()
  15.     end
  16.  
  17.     local function coroutineStatusOverride(...)
  18.         return "dead"
  19.     end
  20.  
  21.     local function osShutdownOverride()
  22.  
  23.         clearScreen()
  24.  
  25.         rednet.close()
  26.         os.unloadAPI("rednet")
  27.         os.loadAPI("/rom/apis/rednet")
  28.  
  29.         rawset(os, "shutdown", oldOsShutdown)
  30.         rawset(coroutine, "status", oldCoroutineStatus)
  31.  
  32.         local ok, err = pcall(mainFunc)
  33.  
  34.         if not ok then
  35.             clearScreen()
  36.             pcall( function()
  37.                 if type(errFunc) == "function" then
  38.                     errFunc(err)
  39.                 else
  40.                     printError(err)
  41.                     print("Press any key to continue")
  42.                     os.pullEvent("key")
  43.                 end
  44.             end )
  45.         end
  46.  
  47.         os.shutdown()
  48.  
  49.     end
  50.  
  51.     rawset(os, "shutdown", osShutdownOverride)
  52.     rawset(coroutine, "status", coroutineStatusOverride)
  53.  
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement