Operating system for OpenComputers
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

24 строки
843B

  1. function loadfile(p) -- reads file *p* and returns a function if possible
  2. local f = fs.open(p,"rb")
  3. local c = f:read("*a")
  4. f:close()
  5. return load(c,p,"t")
  6. end
  7. function runfile(p,...) -- runs file *p* with arbitrary arguments in the current thread
  8. return loadfile(p)(...)
  9. end
  10. function os.spawnfile(p,n) -- spawns a new process from file *p* with name *n*
  11. return os.spawn(function() xpcall(loadfile(p),function(e) dprint(e.."\n"..debug.traceback) end) end,n)
  12. end
  13. function require(f) -- searches for a library with name *f* and returns what the library returns, if possible
  14. local lib = os.getenv("LIB") or "/boot/lib"
  15. for d in lib:gmatch("[^\n]+") do
  16. if fs.exists(d.."/"..f) then
  17. return runfile(d.."/"..f)
  18. elseif fs.exists(d.."/"..f..".lua") then
  19. return runfile(d.."/"..f..".lua")
  20. end
  21. end
  22. error("library not found: "..f)
  23. end