Skip to content

Commit 29bd4f8

Browse files
committed
specify the root of the patch
1 parent 7d8eda8 commit 29bd4f8

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

src/lualib/packageloader.lua

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local package = package
66
local string = string
77
local io = io
88

9-
global load, print, setmetatable, table, type, tostring, ipairs, require
9+
global load, print, setmetatable, table, type, tostring, ipairs, require, error
1010

1111
local dir_sep, temp_sep, temp_marker = package.config:match "(.)\n(.)\n(.)"
1212
local temp_pat = "[^"..temp_sep.."]+"
@@ -17,14 +17,20 @@ local function load_zips(zipnames)
1717
end
1818
local n = 0
1919
local r = {}
20-
for name in zipnames:gmatch "[^:;]+" do
20+
for fullname in zipnames:gmatch "[^:;]+" do
21+
local name, root = fullname:match "(.-)@(.*)"
22+
if name then
23+
root = root .. "/"
24+
else
25+
name = fullname
26+
end
2127
local zf = zip.open(name, "r")
2228
if not zf then
2329
-- print("Can't open patch", name)
2430
else
2531
-- print("Load patch", name)
2632
n = n + 1
27-
r[n] = zf
33+
r[n] = { zip = zf, root = root }
2834
end
2935
end
3036
r.n = n
@@ -40,10 +46,24 @@ local file_load = file.load
4046
local file_exist = file.exist
4147

4248
if zipfile then
43-
local function find_file(cache, name)
49+
local function find_file(cache, fullname)
50+
local name = fullname:match "%./(.*)" or fullname
4451
for i = zipfile.n, 1, -1 do
45-
if zipfile[i]:exist(name) then
46-
cache[name] = zipfile[i]
52+
local root = zipfile[i].root
53+
local name_in_zip
54+
if root then
55+
local n = #root
56+
if name:sub(1, n) == root then
57+
name_in_zip = name:sub(n+1)
58+
end
59+
else
60+
name_in_zip = name
61+
end
62+
local zf = zipfile[i].zip
63+
if name_in_zip and zf:exist(name_in_zip) then
64+
cache[name] = function()
65+
return zf:readfile(name_in_zip)
66+
end
4767
-- print(name, "in zipfile", i)
4868
return cache[name]
4969
end
@@ -52,12 +72,11 @@ if zipfile then
5272
local list
5373
local names_cache = setmetatable({}, { __index = find_file})
5474

55-
function file_load(fullname)
56-
local name = fullname:match "%./(.*)" or fullname
57-
return names_cache[name]:readfile(name)
75+
function file_load(name)
76+
local loader = names_cache[name] or error ("Can't load ".. name)
77+
return loader()
5878
end
59-
function file_exist(fullname)
60-
local name = fullname:match "%./(.*)" or fullname
79+
function file_exist(name)
6180
return names_cache[name] ~= nil
6281
end
6382
file.local_load = file.load
@@ -69,9 +88,13 @@ if zipfile then
6988
local r = {}
7089
local n = 1
7190
for i = zipfile.n, 1, -1 do
72-
local flist = zipfile[i]:list()
91+
local flist = zipfile[i].zip:list()
92+
local root = zipfile[i].root
7393
for j = 1, #flist do
7494
local name = flist[j]
95+
if root then
96+
name = root and root .. name
97+
end
7598
if tmp[name] == nil then
7699
tmp[name] = true
77100
-- todo : add path of name

src/service/start.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ end
7070

7171
local cleanup = util.func_chain()
7272

73+
local function skip_frame()
74+
function app.frame()
75+
ltask.mainthread_run(function() end)
76+
end
77+
end
78+
7379
local function init(arg)
7480
if arg == nil then
7581
error "No command line args"
@@ -121,12 +127,13 @@ local function init(arg)
121127
}
122128

123129
if type(callback) ~= "table" then
130+
skip_frame()
124131
soluna_app.close_window()
125132
return
126133
end
127134

128135
local frame_cb = callback.frame
129-
136+
130137
local messages = { "mouse_move", "mouse_button", "mouse_scroll", "mouse", "window_resize", "char", "key" }
131138
local avail = {}
132139
for _, v in ipairs(messages) do
@@ -152,9 +159,7 @@ local function init(arg)
152159
local function render_frame(count)
153160
local ok, err = xpcall(frame, traceback, count)
154161
if not ok then
155-
function app.frame()
156-
ltask.mainthread_run(function() end)
157-
end
162+
skip_frame()
158163
error(err)
159164
end
160165
end
@@ -188,6 +193,7 @@ ltask.fork(function()
188193

189194
local ok , err = pcall(init, args)
190195
if not ok then
196+
ltask.mainthread_run(function() end)
191197
ltask.log.error(err)
192198
soluna_app.quit()
193199
end

0 commit comments

Comments
 (0)