From 3c8ec4cabc75b27b8558702e27214da6f76c24fa Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 20 Dec 2019 01:51:27 +1100 Subject: [PATCH] fixed some stupid require() behavior --- module/loadfile.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/module/loadfile.lua b/module/loadfile.lua index 5c73784..4e305e3 100644 --- a/module/loadfile.lua +++ b/module/loadfile.lua @@ -13,17 +13,18 @@ function os.spawnfile(p,n,...) -- spawns a new process from file *p* with name * 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 - local lib = os.getenv("LIB") or "/boot/lib" - for d in lib:gmatch("[^\n]+") do - if fs.exists(d.."/"..f) then - _G.libs[f] = runfile(d.."/"..f) - elseif fs.exists(d.."/"..f..".lua") then - _G.libs[f] = runfile(d.."/"..f..".lua") + if not _G.libs[f] then + local lib = os.getenv("LIB") or "/boot/lib" + for d in lib:gmatch("[^\n]+") do + if fs.exists(d.."/"..f) then + _G.libs[f] = runfile(d.."/"..f) + elseif fs.exists(d.."/"..f..".lua") then + _G.libs[f] = runfile(d.."/"..f..".lua") + end end end if _G.libs[f] then return _G.libs[f] - else - error("library not found: "..f) end + error("library not found: "..f) end