function loadfile(p) -- string -- function -- reads file *p* and returns a function if possible local f = io.open(p,"rb") local c = f:read("*a") f:close() return load(c,p,"t") end function runfile(p,...) -- string -- -- runs file *p* with arbitrary arguments in the current thread return loadfile(p)(...) end function os.spawnfile(p,n,...) -- string string -- number -- spawns a new process from file *p* with name *n*, with arguments following *n*. local tA = {...} return os.spawn(function() local res={pcall(loadfile(p), table.unpack(tA))} computer.pushSignal("process_finished", os.pid(), table.unpack(res)) dprint(table.concat(res)) end,n or p) end _G.package = {} package.loaded = {computer=computer,component=component,fs=fs,buffer=buffer,table=table,string=string,package=package,os=os,math=math,coroutine=coroutine} 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 if not package.loaded[f] or force then local lib = os.getenv("LIB") or "/boot/lib\n/pkg/lib" local ln = f:gsub("%.","/") for d in lib:gmatch("[^\n]+") do if fs.isDirectory(d.."/"..ln) then package.loaded[f] = runfile(d.."/"..ln.."/init.lua") elseif fs.exists(d.."/"..ln..".lua") then package.loaded[f] = runfile(d.."/"..ln..".lua") end end end if package.loaded[f] then return package.loaded[f] end error("library not found: "..f) end function reload(f) -- string -- table -- Reloads library *f* from disk into memory. return require(f,true) end