@@ -6,7 +6,7 @@ local package = package
66local string = string
77local 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
1111local dir_sep , temp_sep , temp_marker = package.config :match " (.)\n (.)\n (.)"
1212local 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
4046local file_exist = file .exist
4147
4248if 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
0 commit comments