Created
March 24, 2017 11:58
-
-
Save wujiyu115/5343d8c85401df42a9c7f6c464678442 to your computer and use it in GitHub Desktop.
lua:check_diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- @Author: ejoy | |
-- @Date: 2017-03-24 19:58:07 | |
-- @Last Modified by: ejoy | |
-- @Last Modified time: 2017-03-24 19:58:09 | |
local function check_tb_diff(fa, sfa) | |
if not fa and not sfa then | |
return true | |
end | |
if not fa or not sfa then | |
return false | |
end | |
local rs | |
for k,v in pairs(fa) do | |
if type(v) == "table" then | |
rs = check_tb_diff(v, sfa[k] or {}) | |
if not rs[1]then | |
return rs | |
end | |
elseif sfa[k] ~= v then | |
return {false, k, v, sfa[k]} | |
end | |
end | |
for k,v in pairs(sfa) do | |
if type(v) == "table" then | |
rs = check_tb_diff(v, fa[k] or {}) | |
if not rs[1] then | |
return rs | |
end | |
elseif fa[k] ~= v then | |
return {false, k, v, fa[k]} | |
end | |
end | |
return true | |
end | |
local t1 = { | |
a = "bbbbbb", | |
b = { | |
ba = 1 | |
}, | |
c = "ffffff", | |
} | |
local t2 = { | |
a = "bbbbbb", | |
b = { | |
ba = 2 | |
}, | |
c = "ffffff", | |
} | |
local rs = check_tb_diff(t1, t2) | |
print(table.unpack(rs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment