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.

35 lines
1.3KB

  1. function loadfile(p) -- string -- function -- reads file *p* and returns a function if possible
  2. local f = io.open(p,"rb")
  3. local c = f:read("*a")
  4. f:close()
  5. return load(c,p,"t")
  6. end
  7. function runfile(p,...) -- string -- -- runs file *p* with arbitrary arguments in the current thread
  8. return loadfile(p)(...)
  9. end
  10. _G.package = {}
  11. package.path="/boot/lib/?.lua;/pkg/lib/?.lua;/boot/lib/?/init.lua;/pkg/lib/?/init.lua;./?;./?.lua;./?/init.lua"
  12. package.loaded = {buffer=buffer, component=component, computer=computer, coroutine=coroutine, fs=fs, math=math, os=os, package=package, string=string, table=table}
  13. package.alias = {filesystem="fs"}
  14. function require(f,force) -- string boolean -- table -- searches for a library with name *f* and returns what the library returns, if possible. if *force* is set, loads the library even if it is cached
  15. f=package.alias[f] or f
  16. if not package.loaded[f] or force then
  17. local ln = f:gsub("%.","/")
  18. for d in package.path:gmatch("[^;]+") do
  19. local p = d:gsub("%?",ln)
  20. if fs.exists(p) and not fs.isDirectory(p) then
  21. package.loaded[f] = runfile(p)
  22. break
  23. end
  24. end
  25. end
  26. if package.loaded[f] then
  27. return package.loaded[f]
  28. end
  29. error("library not found: "..f)
  30. end
  31. function reload(f) -- string -- table -- Reloads library *f* from disk into memory.
  32. return require(f,true)
  33. end