forked from bluecube/factorio-highcontrast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.lua
36 lines (27 loc) · 1.02 KB
/
loader.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
local Loader = {}
Loader.path_substitutions = {}
--- Loads Factorio data files from a list of mods.
-- Paths contain a list of mods that are loaded.
-- First one has to be core.
-- Output is stored in the global variables data.raw, after calling this function,
-- the function replace_path can be used.
function Loader.load_data(paths)
for i = 1, #paths do
if i == 1 then
package.path = paths[i] .. "/lualib/?.lua;" .. package.path
require("dataloader")
end
local old_path = package.path
package.path = paths[i] .. "/?.lua;" .. package.path
dofile(paths[i] .. "/data.lua")
extended_path = "./" .. paths[i]
Loader.path_substitutions["__" .. extended_path:gsub("^.*/([^/]+)/?$", "%1") .. "__"] = paths[i]
package.path = old_path
end
end
--- Replace __mod__ references in path.
-- Uses the global variable path_substitutions
function Loader.expand_path(path)
return path:gsub("__[a-zA-Z0-9-_]*__", Loader.path_substitutions)
end
return Loader