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
|
local args = ...
require 'utility'
local fs = require 'bee.filesystem'
local path_filter = require 'path_filter'
local function scan(root, filter)
local result = {}
local len = #root:string()
local name = root:string():sub(len+2):gsub('/', '\\')
if filter(name) then
OUT:push('log', '过滤文件:', root:string())
else
result[#result+1] = root
end
local i = 0
return function ()
i = i + 1
local current = result[i]
if not current then
return nil
end
if fs.is_directory(current) then
for path in current:list_directory() do
local name = path:string():sub(len+2):gsub('/', '\\')
if filter(name) then
OUT:push('log', '过滤文件:', path:string())
else
result[#result+1] = path
end
end
end
return current
end
end
local ignore = {}
for _, name in ipairs(args.ignored) do
if name:sub(1, 1) ~= '!' then
ignore[#ignore+1] = name
end
end
local filter = path_filter(ignore)
for path in scan(fs.path(args.root), filter) do
local ok, msg = IN:pop()
if ok and msg == 'stop' then
OUT:push 'stop'
return
end
if path:extension():string() == '.lua' then
local buf = io.load(path)
if buf then
OUT:push('file', {
path = fs.absolute(path):string(),
buf = buf,
})
end
end
end
OUT:push 'ok'
|