Sirshark10

Untitled

Jul 5th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 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. local eeprom = component.list("eeprom")()
  12. computer.getBootAddress = function()
  13. return boot_invoke(eeprom, "getData")
  14. end
  15. computer.setBootAddress = function(address)
  16. return boot_invoke(eeprom, "setData", address)
  17. end
  18.  
  19. do
  20. local screen = component.list("screen")()
  21. local gpu = component.list("gpu")()
  22. if gpu and screen then
  23. boot_invoke(gpu, "bind", screen)
  24. end
  25. end
  26.  
  27. local function tryLoadFrom(address)
  28. local handle, reason = boot_invoke(address, "open", "/init.lua")
  29. if not handle then
  30. return nil, reason
  31. end
  32. local buffer = ""
  33. repeat
  34. local data, reason = boot_invoke(address, "read", handle, math.huge)
  35. if not data and reason then
  36. return nil, reason
  37. end
  38. buffer = buffer .. (data or "")
  39. until not data
  40. boot_invoke(address, "close", handle)
  41. return load(buffer, "=init")
  42. end
  43.  
  44. local init, reason
  45. if computer.getBootAddress() then
  46. init, reason = tryLoadFrom(computer.getBootAddress())
  47. end
  48.  
  49. if not init then
  50. computer.setBootAddress()
  51. for address in component.list("filesystem") do
  52. init, reason = tryLoadFrom(address)
  53. if init then
  54. computer.setBootAddress(address)
  55. break
  56. end
  57. end
  58. end
  59. if not init then
  60. error("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0)
  61. end
  62. a = 1000
  63. for i=1,5 do
  64. computer.beep(a)
  65. a = a+1
  66. end
  67. init()
Advertisement
Add Comment
Please, Sign In to add comment