local table_ = "actor_stage_up";
table.getall = function(data)
if data == nil
then
sprint("table.getall data is nil");
end
if(type(data)=="table")
then
local num = 0;
for k, v in pairs(data)
do
num = num+1;
end
return num;
else
sprint("table.getall data is not table");
end
return 0;
end
core = {};
core.print= function(data)
if data == nil then
print("core.print data is nil");
end
if(type(data)=="table") then
for k, v in pairs(data) do
print("k="..tostring(k).."\tv="..tostring(v));
if(type(v) == "table") then
core.print(v);
end
end
else
print(tostring(data));
end
end
function deal_with(table_,file)
local path = "old\\";
require (path..table_);
local all_table = "gd_"..table_;
local old_table = _G[all_table];
path = "new\\";
require (path..table_);
all_table = "gd_"..table_;
local t_wite_list = {}; --差异字段最新列表 t_wite_list[k_index][k_key] = v_value;
local new_table = _G[all_table];
--找新表 新表里的内容和老表的内容不符合 则写入更新文件
for k_index,v_info_list in pairs (new_table) do
for k_key,v_value in pairs(v_info_list) do
if old_table[k_index] == nil or old_table[k_index][k_key] == nil then --新数据在老数据里没找到 代表这条数据是新创建的数据
--写入更新文件
--wite_update_file(file,all_table,k_index,k_key,v_value);
if t_wite_list[k_index] == nil then
t_wite_list[k_index] = {};
end
t_wite_list[k_index][k_key] = v_value;
elseif v_value ~= old_table[k_index][k_key] then --新数据和老数据不对等
--写入更新文件
--wite_update_file(file,all_table,k_index,k_key,v_value);
if t_wite_list[k_index] == nil then
t_wite_list[k_index] = {};
end
t_wite_list[k_index][k_key] = v_value;
end
end
end
for k_index,v_value_list in pairs(t_wite_list) do
--一条数据 如果差异超过5条 将这一整条数据写入
--core.print(v_value_list);
--print("==========");
if old_table[k_index] == nil or table.getall(v_value_list) > 5 then
wite_all_update_file(file,all_table,k_index,new_table[k_index]);
else
for k_key,v_value in pairs(v_value_list) do
wite_one_update_file(file,all_table,k_index,k_key,v_value);
end
end
end
--[[
for k,v in pairs (old_table) do
for i,j in pairs(v) do
if new_table[k][i] ~= nil then
if j ~= new_table[k][i] then
local t = type(j);
if t == "number" then
file:write(all_table)
file:write("["..k.."][\""..i.."\"] = ");
file:write(tonumber(second_table[k][i]));
file:write(";\n");
elseif t == "string" then
file:write(all_table)
file:write("["..k.."][\""..i.."\"] = ");
file:write("\"");
file:write(tostring(second_table[k][i]));
file:write("\"");
file:write(";\n");
end
end
end
end
end]]--
end
--写入一个table的整个字段
function wite_all_update_file(t_file,t_table_name,t_key_index,t_value_list)
if t_file ~= nil then
t_file:write(t_table_name);
t_file:write("[");
t_file:write(t_key_index);
t_file:write("]");
t_file:write(" = {");
for k_value_key,v_value_value in pairs(t_value_list) do
t_file:write(k_value_key);
t_file:write('=');
if type(v_value_value) == "string" then
v_value_value = string.gsub(v_value_value,"\n","\\n");
t_file:write('"');
t_file:write(v_value_value);
t_file:write('"');
else
t_file:write(v_value_value);
end
t_file:write(', ');
end
t_file:write("};\n");
end
end
--写入一个talbe的单个字段
function wite_one_update_file(t_file,t_table_name,t_key_index,t_value_name,t_value)
if t_file ~= nil then
t_file:write(t_table_name);
t_file:write("[");
t_file:write(t_key_index);
t_file:write("]");
t_file:write('.');
t_file:write(t_value_name);
t_file:write('=');
if type(t_value) == "string" then
t_value = string.gsub(t_value,"\n","\\n");
t_file:write('"');
t_file:write(t_value);
t_file:write('"');
else
t_file:write(t_value);
end
t_file:write(";\n");
end
end
local file = io.open("update_data.sd","w");
local file1 = io.open("table_list.txt", "r");
if file1 ~= nil then
for one_line in file1:lines() do
--print(tostring(one_line))
deal_with(tostring(one_line),file);
end
end
file:close();
file1:close();
l