314bc5df
zhengshouren
提交服务器初始代码
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
local function formatFileName(filename)
filename = string.trim(filename)
local basename = filename:match("([^/]+)%.lua$")
if not basename then return end
local loadname = filename:match("^src/([^.]+)%.lua$")
loadname = loadname:gsub('/', '.')
return basename, loadname
end
local function travCsv(rootPath, pathes)
pathes = pathes or {}
local modified = false
local ok, files, iter = pcall(lfs.dir, rootPath)
if not ok then return modified end
for entry in files, iter do
-- 过滤 . 开始的字符串包括 . .. .git .开头的文件名
if string.byte(entry, 1) ~= 46 then
local pathfile = rootPath .. '/' .. entry
local attrs = lfs.attributes(pathfile)
if attrs.mode == 'directory' then
modified = travCsv(pathfile, pathes) or modified
else
local basename, loadname = formatFileName(pathfile)
|
314bc5df
zhengshouren
提交服务器初始代码
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
end
end
end
end
return modified
end
-- 每分钟检查是否有更改
local file2timeMap = {}
local function handle_timeout()
if travCsv("src/csvdata", file2timeMap) then
sharedata.update("csvdata", csvdb)
end
skynet.timeout(100*5, handle_timeout)
end
skynet.start(function ()
travCsv("src/csvdata", file2timeMap)
sharedata.new("csvdata", csvdb)
-- handle_timeout()
end)
|