1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-22 03:54:20 -05:00

add basic submodule support to require

This commit is contained in:
XeonSquared 2020-06-25 16:29:12 +10:00
parent 5e9baee9fa
commit 522d456433

View File

@ -12,15 +12,16 @@ function os.spawnfile(p,n,...) -- string string -- number -- spawns a new proces
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) 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 end
_G.package = {} _G.package = {}
package.loaded = {computer=computer,component=component,fs=fs,buffer=buffer} 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 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 if not package.loaded[f] or force then
local lib = os.getenv("LIB") or "/boot/lib\n/pkg/lib" local lib = os.getenv("LIB") or "/boot/lib\n/pkg/lib"
local ln = f:gsub("%.","/")
for d in lib:gmatch("[^\n]+") do for d in lib:gmatch("[^\n]+") do
if fs.exists(d.."/"..f) then if fs.isDirectory(d.."/"..ln) then
package.loaded[f] = runfile(d.."/"..f) package.loaded[f] = runfile(d.."/"..ln.."/init.lua")
elseif fs.exists(d.."/"..f..".lua") then elseif fs.exists(d.."/"..ln..".lua") then
package.loaded[f] = runfile(d.."/"..f..".lua") package.loaded[f] = runfile(d.."/"..ln..".lua")
end end
end end
end end