Advertisement
Arc13

arcLoader

Aug 5th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. local component_invoke = component.invoke
  2. function boot_invoke(address, method, ...)
  3. local result = table.pack(pcall(component_invoke, address, method, ...))
  4. if not result[1] then
  5. return nil, result[2]
  6. else
  7. return table.unpack(result, 2, result.n)
  8. end
  9. end
  10.  
  11. function stream(fd,file,mode)
  12. checkArg(1,fd,'number')
  13. assert(fd>=0,'fd must be >= 0. 0 is input, 1 is stdout, 2 is stderr')
  14. if file then
  15. if type(file) == "string" then
  16. local result, reason = io.open(file, mode)
  17. if not result then
  18. error(reason, 2)
  19. end
  20. file = result
  21. elseif not io.type(file) then
  22. error("bad argument #1 (string or file expected, got " .. type(file) .. ")", 2)
  23. end
  24. require("process").info().data.io[fd] = file
  25. end
  26. return require("process").info().data.io[fd]
  27. end
  28.  
  29. function input(file)
  30. return stream(0, file, 'r')
  31. end
  32.  
  33. function write(...)
  34. return output():write(...)
  35. end
  36.  
  37. -- backwards compatibility, may remove later
  38. local eeprom = component.list("eeprom")()
  39. computer.getBootAddress = function()
  40. return boot_invoke(eeprom, "getData")
  41. end
  42. computer.setBootAddress = function(address)
  43. return boot_invoke(eeprom, "setData", address)
  44. end
  45.  
  46. local screen = component.list("screen")()
  47. local gpu = component.list("gpu")()
  48. if gpu and screen then
  49. boot_invoke(gpu, "bind", screen)
  50. end
  51.  
  52. fs = component.list("filesystem")
  53.  
  54. for k, v in pairs(fs) do
  55. write(k)
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement