Operating system for OpenComputers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2KB

  1. io = {}
  2. function io.open(path,mode) -- string string -- table -- Open file *path* in *mode*. Returns a buffer object.
  3. local f,e = fs.open(path, mode)
  4. if not f then return false, e end
  5. return buffer.new(mode,f)
  6. end
  7. function io.input(fd) -- table -- table -- Sets the default input stream to *fd* if provided, either as a buffer as a path. Returns the default input stream.
  8. if type(fd) == "string" then
  9. fd=io.open(fd,"rbt")
  10. end
  11. if fd then
  12. os.setenv("STDIN",fd)
  13. end
  14. return os.getenv("STDIN")
  15. end
  16. function io.output(fd) -- table -- table -- Sets the default output stream to *fd* if provided, either as a buffer as a path. Returns the default output stream.
  17. if type(fd) == "string" then
  18. fd=io.open(fd,"wb")
  19. end
  20. if fd then
  21. os.setenv("STDOUT",fd)
  22. end
  23. return os.getenv("STDOUT")
  24. end
  25. function io.read(...) -- Reads from the default input stream.
  26. return io.input():read(...)
  27. end
  28. function io.write(...) -- Writes its arguments to the default output stream.
  29. io.output():write(...)
  30. end
  31. function print(...) -- Writes each argument to the default output stream, separated by space.
  32. for k,v in ipairs({...}) do
  33. io.write((k>1 and "\t" or "")..tostring(v))
  34. end
  35. io.write("\n")
  36. end