-
Notifications
You must be signed in to change notification settings - Fork 0
/
getBasalt.lua
90 lines (85 loc) · 2.64 KB
/
getBasalt.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
local config
local basalt = {}
local data = {}
local loaded = {}
local baseRequire = require
_ENV.require = function(path)
if(data[path]~=nil)then
if(loaded[path]==nil)then
loaded[path] = load(data[path], nil, "t", _ENV)()
end
return loaded[path]
end
if(data["libraries/"..path]~=nil)then
if(loaded["libraries/"..path]==nil)then
loaded["libraries/"..path] = load(data["libraries/"..path], nil, "t", _ENV)()
end
return loaded["libraries/"..path]
end
if(data["elements/"..path]~=nil)then
if(loaded["elements/"..path]==nil)then
loaded["elements/"..path] = load(data["elements/"..path], nil, "t", _ENV)()
end
return loaded["elements/"..path]
end
if(data["extensions/"..path]~=nil)then
if(loaded["extensions/"..path]==nil)then
loaded["extensions/"..path] = load(data["extensions/"..path], nil, "t", _ENV)()
end
return loaded["extensions/"..path]
end
return baseRequire(path)
end
local function getConfig()
if(config==nil)then
local github = "https://raw.githubusercontent.com/Pyroxenium/basalt-docs/main/config.json"
if(github~=nil)then
local response = http.get(github)
if(response==nil)then
error("Couldn't get the config file from github!")
end
config = textutils.unserializeJSON(response.readAll())
response.close()
return config
else
error("Couldn't find the github path in the settings basalt.github!")
end
end
return config
end
local files = getConfig().versions
local webAccess = {}
for k,v in pairs(files)do
if(k~="elements")and(k~="libraries")and(k~="extensions")then
webAccess[k] = v[2]
end
if(k=="libraries")then
for k,v in pairs(v)do
webAccess["libraries/"..k] = v[2]
end
end
if(k=="elements")then
for k,v in pairs(v)do
if(k=="BasicElement")or(k=="VisualElement")or(k=="Container")or(k=="BaseFrame")then
webAccess["elements/"..k] = v[2]
end
end
end
end
print("Loading the core files from github...")
local parallelAccess = {}
for k,v in pairs(webAccess)do
table.insert(parallelAccess, function()
local url = v
local response = http.get(url)
if(response==nil)then
error("Couldn't get the file "..k.." from github!")
end
local webData = response.readAll()
print("Loaded "..k.."!")
data[k] = webData
end)
end
parallel.waitForAll(unpack(parallelAccess))
basalt = load(data["main"], nil, "t", _ENV)()
return basalt