added the ability to reload libraries to the loadfile module

This commit is contained in:
Izaya 2020-04-12 01:59:20 +10:00
parent 0cdd70e917
commit 2327dc9c18

View File

@ -13,8 +13,8 @@ function os.spawnfile(p,n,...) -- spawns a new process from file *p* with name *
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}
function require(f) -- searches for a library with name *f* and returns what the library returns, if possible function require(f,force) -- 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] then if not package.loaded[f] or force then
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
@ -29,3 +29,6 @@ function require(f) -- searches for a library with name *f* and returns what the
end end
error("library not found: "..f) error("library not found: "..f)
end end
function reload(f)
return require(f,true)
end