mirror of
https://github.com/LDDestroier/CC/
synced 2025-05-25 08:34:05 +00:00
Create netrequire.lua
This commit is contained in:
parent
74cbc6b9b9
commit
b240164015
30
netrequire.lua
Normal file
30
netrequire.lua
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
local function netrequire(_name, alwaysDownload, ...)
|
||||||
|
assert(type(_name) == "string", "API name must be a string")
|
||||||
|
local DL_path = ".netrequire_storage"
|
||||||
|
|
||||||
|
local name
|
||||||
|
if _name:sub(-4, -1) ~= ".lua" then
|
||||||
|
name = _name .. ".lua"
|
||||||
|
else
|
||||||
|
name = _name
|
||||||
|
end
|
||||||
|
|
||||||
|
if (not fs.exists(fs.combine(DL_path, name))) or alwaysDownload then
|
||||||
|
local url = "https://github.com/LDDestroier/CC/raw/master/netrequire/" .. name
|
||||||
|
local 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)(...)
|
||||||
|
else
|
||||||
|
error("Cannot find any such API '" .. name .. "'")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return loadfile(fs.combine(DL_path, name))(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return netrequire
|
Loading…
x
Reference in New Issue
Block a user