From 71b2e93fd28c02dfab3cf9e1f4c535797c847e46 Mon Sep 17 00:00:00 2001 From: huahua132 <958677003@qq.com> Date: Mon, 30 Sep 2024 18:14:20 +0800 Subject: [PATCH] =?UTF-8?q?sharedata=20=E8=80=83=E8=99=91=E7=BA=B5?= =?UTF-8?q?=E8=A1=A8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lualib/skynet-fly/sharedata.lua | 96 ++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/lualib/skynet-fly/sharedata.lua b/lualib/skynet-fly/sharedata.lua index c74729885..da19c34cb 100644 --- a/lualib/skynet-fly/sharedata.lua +++ b/lualib/skynet-fly/sharedata.lua @@ -14,6 +14,7 @@ local setmetatable = setmetatable local pairs = pairs local table = table local ipairs = ipairs +local type = type local g_mode_map = {} local g_data_map = {} @@ -197,58 +198,69 @@ function M:builder() local data_table = self.data_table for index, oneCfg in pairs(data_table) do - for k,v in pairs(oneCfg) do - local kfunc = check_func_map[k] - if kfunc then - local isok,err = kfunc(v) - if not isok then - log.warn_fmt("check field err filepath[%s] idx[%s] fieldname[%s] errinfo[%s]", file_path, index, k, err) + if type(oneCfg) == 'table' then + for k,v in pairs(oneCfg) do + local kfunc = check_func_map[k] + if kfunc then + local isok,err = kfunc(v) + if not isok then + log.warn_fmt("check field err filepath[%s] idx[%s] fieldname[%s] errinfo[%s]", file_path, index, k, err) + end end end - end - if check_line_func then - local isok,err = check_line_func(oneCfg) - if not isok then - log.warn_fmt("check line err filepath[%s] idx[%s] errinfo[%s]", file_path, index, err) - end - end - - for name,field_list in pairs(map_list_map_fields) do - local map = map_list_map[name] - for _,fieldname in ipairs(field_list) do - local v = oneCfg[fieldname] - if not v then - log.warn_fmt("set maplist err field not exists name[%s] filepath[%s] idx[%s] fieldname[%s]", name, file_path, index, fieldname) - break - end - if not map[v] then - map[v] = {} + if check_line_func then + local isok,err = check_line_func(oneCfg) + if not isok then + log.warn_fmt("check line err filepath[%s] idx[%s] errinfo[%s]", file_path, index, err) end - map = map[v] end - table.insert(map, oneCfg) - end - for name,field_list in pairs(map_map_fields) do - local map = map_map[name] - local len = #field_list - for i = 1, len do - local fieldname = field_list[i] - local v = oneCfg[fieldname] - if not v then - log.warn_fmt("set map err field not exists name[%s] filepath[%s] idx[%s] fieldname[%s]", name, file_path, index, fieldname) - break - end - if i < len then + for name,field_list in pairs(map_list_map_fields) do + local map = map_list_map[name] + for _,fieldname in ipairs(field_list) do + local v = oneCfg[fieldname] + if not v then + log.warn_fmt("set maplist err field not exists name[%s] filepath[%s] idx[%s] fieldname[%s]", name, file_path, index, fieldname) + break + end if not map[v] then map[v] = {} end map = map[v] - else - if map[v] then - log.warn_fmt("set map repeat err field not exists name[%s] filepath[%s] idx[%s] fieldname[%s]", name, file_path, index, fieldname) + end + table.insert(map, oneCfg) + end + + for name,field_list in pairs(map_map_fields) do + local map = map_map[name] + local len = #field_list + for i = 1, len do + local fieldname = field_list[i] + local v = oneCfg[fieldname] + if not v then + log.warn_fmt("set map err field not exists name[%s] filepath[%s] idx[%s] fieldname[%s]", name, file_path, index, fieldname) + break end - map[v] = oneCfg + if i < len then + if not map[v] then + map[v] = {} + end + map = map[v] + else + if map[v] then + log.warn_fmt("set map repeat err field not exists name[%s] filepath[%s] idx[%s] fieldname[%s]", name, file_path, index, fieldname) + end + map[v] = oneCfg + end + end + end + else + --one 参数表 + local kfunc = check_func_map[index] + if kfunc then + local isok,err = kfunc(oneCfg) + if not isok then + log.warn_fmt("check field err filepath[%s] idx[%s] fieldname[%s] errinfo[%s]", file_path, index, oneCfg, err) end end end