made require pull from a shared library pool

This commit is contained in:
Izaya 2019-12-19 16:14:48 +11:00
parent 1cb85bd5e8
commit 6ad21c7832

View File

@ -11,14 +11,19 @@ function os.spawnfile(p,n,...) -- spawns a new process from file *p* with name *
local tA = {...} local tA = {...}
return os.spawn(function() computer.pushSignal("process_finished", os.pid(), pcall(loadfile(p), table.unpack(tA))) end,n or p) return os.spawn(function() computer.pushSignal("process_finished", os.pid(), pcall(loadfile(p), table.unpack(tA))) end,n or p)
end end
_G.libs = {computer=computer,component=component}
function require(f) -- searches for a library with name *f* and returns what the library returns, if possible function require(f) -- searches for a library with name *f* and returns what the library returns, if possible
local lib = os.getenv("LIB") or "/boot/lib" local lib = os.getenv("LIB") or "/boot/lib"
for d in lib:gmatch("[^\n]+") do for d in lib:gmatch("[^\n]+") do
if fs.exists(d.."/"..f) then if fs.exists(d.."/"..f) then
return runfile(d.."/"..f) _G.libs[f] = runfile(d.."/"..f)
elseif fs.exists(d.."/"..f..".lua") then elseif fs.exists(d.."/"..f..".lua") then
return runfile(d.."/"..f..".lua") _G.libs[f] = runfile(d.."/"..f..".lua")
end end
end end
if _G.libs[f] then
return _G.libs[f]
else
error("library not found: "..f) error("library not found: "..f)
end end
end