-
Notifications
You must be signed in to change notification settings - Fork 8
/
elploader.lua
81 lines (70 loc) · 1.54 KB
/
elploader.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
local elp = require "elpack"
local loader = {}
local register_mod = {}
function loader.load(mod,elpfile)
if type(elpfile) == "table" then
local last = 0
local tmp = {}
local n = #elpfile
for _, filename in ipairs(elpfile) do
local e, header, v1, v2 = elp.open(filename)
if v1 ~= last then
error("Invalid patch file version ".. filename)
end
last = v2
local header, v = elp.decompress(header)
e:init(header)
tmp[n] = e
n = n - 1
end
register_mod[mod] = tmp
else
local e, header, v1, v2 = elp.open(elpfile)
if v1 ~= 0 then
error(elpfile .. " is a patch file")
end
local header, v = elp.decompress(header)
e:init(header)
register_mod[mod] = e
end
end
local function elp_loader(modname, data)
return elp.load(data, "@" .. modname)(modname)
end
local function load_file(m, name)
if type(m) == "table" then
local index = nil
for i = 1, #m do
index = m[i]:load(name, index)
if index == nil then
return
end
if type(index) == "string" then
return index
end
end
else
return m:load(name)
end
end
local function elp_searcher(mod)
local pack, name = mod:match("^([^.]+)%.(.+)")
if pack == nil then
return
end
local m = register_mod[pack]
if not m then
return "\n\tno elp '" .. pack .. "'"
end
name = name:gsub("%.", "/")
local block = load_file(m, name .. ".lua")
if not block then
return string.format("\n\tno file '%s' in elp '%s'", name, pack)
end
return elp_loader, block
end
local function main()
table.insert(package.searchers, elp_searcher)
end
main()
return loader