Fraeric123

compat

Dec 22nd, 2021 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. --
  2. --   Library code used by the example programs
  3. --   Computercraft version
  4. --
  5.  
  6. --   Utility for calling a function and printing the
  7. --   error message if it throws an exception
  8.  
  9. function try(func, ...)
  10.   ok, result = pcall(func, ...)
  11.   if not ok then
  12.     print("Error: " .. result)
  13.   end
  14. end
  15.  
  16. --   Terminal API compatibility functions
  17.  
  18. screen_width, screen_height = term.getSize()
  19.  
  20. function setCursor(col, row)
  21.   term.setCursorPos(col, row)
  22. end
  23.  
  24. --   Event API compatibility functions
  25.  
  26. function pull_event()
  27.   return os.pullEvent()
  28. end
  29.  
  30. key_event_name = "char"
  31.  
  32. function key_event_char(e)
  33.   return e[2]
  34. end
  35.  
  36. --   Error message compatibility functions
  37.  
  38. function extractErrorMessage(mess)
  39.   i = string.find(mess, "\n")
  40.   if i then
  41.     mess = string.sub(mess, i - 1)
  42.   end
  43.   i = string.find(mess, ":")
  44.   while i do
  45.     mess = string.sub(mess, i + 1)
  46.     i = string.find(mess, ":")
  47.   end
  48.   return mess
  49. end
  50.  
Add Comment
Please, Sign In to add comment