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
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