--
--   Library code used by the example programs
--   Computercraft version
--

--   Utility for calling a function and printing the
--   error message if it throws an exception

function try(func, ...)
  ok, result = pcall(func, ...)
  if not ok then
    print("Error: " .. result)
  end
end

--  Utility for checking the result of a function call and
--  throwing an exception if it returned an error indication

function check(a, b, ...)
    if a == nil then
        error(b, 0)
    end
    return a, b, ...
end

--  Terminal API compatibility functions

screen_width, screen_height = term.getSize()

function setCursor(col, row)
  term.setCursorPos(col, row)
end

--  Event API compatibility functions

function pull_event()
  return os.pullEvent()
end

key_event_name = "char"

function key_event_char(e)
  return e[2]
end
