From d8a063bd4e7fdb58ecb6b39802a3aae82bf453ca Mon Sep 17 00:00:00 2001 From: LDDestroier Date: Sat, 25 May 2019 23:00:37 -0400 Subject: [PATCH] Added support for os.loadAPI() --- netrequire.lua | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/netrequire.lua b/netrequire.lua index 7eb4c05..f820f85 100644 --- a/netrequire.lua +++ b/netrequire.lua @@ -9,28 +9,42 @@ local function netrequire(_name, alwaysDownload, ...) name = _name end - if (not fs.exists(fs.combine(DL_path, name))) or alwaysDownload then + if fs.exists(fs.combine(DL_path .. "/require", name)) and not alwaysDownload then + return loadfile(fs.combine(DL_path .. "/require", name))(...) + + elseif fs.exists(fs.combine(DL_path .. "/loadAPI", name)) and not alwaysDownload then + os.loadAPI(fs.combine(DL_path .. "/loadAPI", name)) + return _ENV[fs.getName(name)] + + else local url = "https://github.com/LDDestroier/CC/raw/master/netrequire/" .. name local net = http.get(url) if net then url = net.readLine() + local useLoadAPI = net.readLine():sub(1, 4) == "true" net.close() net = http.get(url) if net then local contents = net.readAll() net.close() - local file = fs.open(fs.combine(DL_path, name), "w") - file.write(contents) - file.close() - return loadstring(contents)(...) + if useLoadAPI then + local file = fs.open(fs.combine(DL_path .. "/loadAPI", name), "w") + file.write(contents) + file.close() + os.loadAPI(fs.combine(DL_path .. "/loadAPI", name)) + return _ENV[fs.getName(name)] + else + local file = fs.open(fs.combine(DL_path .. "/require", name), "w") + file.write(contents) + file.close() + return loadstring(contents)(...) + end else error("Couldn't connect to '" .. url .. "'") end else error("Cannot find any such API '" .. name .. "'") end - else - return loadfile(fs.combine(DL_path, name))(...) end end