Added support for os.loadAPI()

This commit is contained in:
LDDestroier 2019-05-25 23:00:37 -04:00 committed by GitHub
parent 19d568af52
commit d8a063bd4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 7 deletions

View File

@ -9,28 +9,42 @@ local function netrequire(_name, alwaysDownload, ...)
name = _name name = _name
end 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 url = "https://github.com/LDDestroier/CC/raw/master/netrequire/" .. name
local net = http.get(url) local net = http.get(url)
if net then if net then
url = net.readLine() url = net.readLine()
local useLoadAPI = net.readLine():sub(1, 4) == "true"
net.close() net.close()
net = http.get(url) net = http.get(url)
if net then if net then
local contents = net.readAll() local contents = net.readAll()
net.close() net.close()
local file = fs.open(fs.combine(DL_path, name), "w") if useLoadAPI then
file.write(contents) local file = fs.open(fs.combine(DL_path .. "/loadAPI", name), "w")
file.close() file.write(contents)
return loadstring(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 else
error("Couldn't connect to '" .. url .. "'") error("Couldn't connect to '" .. url .. "'")
end end
else else
error("Cannot find any such API '" .. name .. "'") error("Cannot find any such API '" .. name .. "'")
end end
else
return loadfile(fs.combine(DL_path, name))(...)
end end
end end