Guest User

ecapi

a guest
Jan 7th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. codes = {}
  2.  
  3. function addCode(code, message)
  4.   codes[code] = {}
  5.   codes[code]["message"] = message
  6.   return
  7. end
  8.  
  9. function lookupCode(code)
  10.   if codes[code] then
  11.     print("Error code "..code.." says: ")
  12.     term.setTextColor(colors.red)
  13.     print(codes[code]["message"])
  14.     term.setTextColor(colors.white)
  15.   else
  16.     print("No such code. Please retry your lookup.")
  17.   end
  18.   return
  19. end
  20.  
  21. function removeCode(code)
  22.   codes[code] = nil
  23.   return
  24. end
  25.  
  26. function printError(code)
  27.   print(codes[code]["messasge"])
  28.   return
  29. end
  30.  
  31. function parseError(func)
  32.   local ok, err = pcall(func)
  33.   if not ok then
  34.     w, h = term.getSize()
  35.     term.setBackgroundColor(colors.blue)
  36.     term.clear()
  37.     term.setTextColor(1)
  38.     term.setCursorPos(math.floor(w-string.len("An error has occurred, causing a crash"))/2, 2)
  39.     print("An error has occurred, causing a crash")
  40.     term.setCursorPos(math.floor(w-string.len(err))/2,4)
  41.     print(err)
  42.     term.setBackgroundColor(colors.black)
  43.     term.setCursorPos(1,h)
  44.     term.clearLine(h)
  45.   end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment