SirBaconBitz

Untitled

Mar 4th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. local isDev = true -- set this for your own development environments, it will make the BSOD print a line number.
  2.  
  3. local function main(argc, argv)
  4. if argc ~= 0 then
  5. if argc == 1 then
  6. if argv[1] == "-help" then
  7. print("Valid arguments -help -test")
  8. return true -- we want to exit but not trigger the BSOD for something this trivial
  9. elseif argv[1] == "-test" then
  10. print("Tested, now running")
  11. else
  12. print("Invalid argument, "..argv[1].." run with -help to see valid arguments")
  13. return true -- we want to exit but not trigger the BSOD for something this trivial
  14. end
  15. else
  16. print("This program only supports 1 argument not "..argc)
  17. return true -- we want to exit but not trigger the BSOD for something this trivial
  18. end
  19. end
  20.  
  21. -- function calls and main code body here
  22.  
  23. return true
  24. end
  25.  
  26. local ok, err = pcall(main, #({...}), {...})
  27.  
  28. if not ok then
  29. -- for the following 2 functions are from my Extended String Library...
  30. local split = function(str, pat) local t = {} local fpat = "(.-)"..pat local last_end = 1local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e + 1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end
  31. local trim = function(str) return (str:gsub("^%s*(.-)%s*$", "%1")) end
  32.  
  33. -- localize these as they are only used here
  34. local setColors = function(bg, txt) if not (term.isColor and term.isColor()) then return false end if txt then term.setTextColor(txt) end if bg then term.setBackgroundColor(bg) end end
  35. local clear = function(col) if col then term.setBackgroundColor(col) end term.clear() end
  36. local cwrite = function(msg, y, offset) local sw,sh = term.getSize() term.setCursorPos(sw/2-#msg/2, (y or (sh/2)) + (offset or 0)) write(msg) end
  37. local errHeader = function(text, y, centre) setColors(colors.white, colors.blue) if centre then cwrite(text, y) else term.setCursorPos(1,y) print(text) end setColors(colors.blue, colors.white) end
  38. local printMsg = function(text, y) term.setCursorPos(1,y) print(text) end
  39. local waitForKey = function() while true do local e,k=os.pullEventRaw("key") if k == 28 or k == 156 then break end end end
  40. local err = split(err,":")
  41. local sw,sh = term.getSize()
  42.  
  43. clear(colors.blue)
  44.  
  45. -- the error headers
  46. errHeader(" ERROR : "..( err[#err-2] and string.upper(err[#err-2]) or "<UNKNOWN>").." ", 2, true)
  47. errHeader(" Error Description ", 7, false)
  48. errHeader(" Reporting the Issue ", sh-7, false)
  49.  
  50. -- BSOD content
  51. printMsg("An error has occurred during runtime with \'"..(err[#err-2] or "<unknown>").."\' and the program has ceased working.", 4)
  52. printMsg(trim((isDev and "Line "..(err[#err-1] and err[#err-1] or "<unknown>")..":" or "")..err[#err]) or "<No error message supplied>",9)
  53. printMsg("If this problem persists please try updating the program with '-update' and if the problem still persists report the issue with '-report'",sh-5)
  54.  
  55. cwrite("Press enter to quit...",sh-1)
  56. waitForKey()
  57.  
  58. term.clear(colors.black)
  59. term.setCursorPos(1,1)
  60. end
Add Comment
Please, Sign In to add comment