Skip to content
Snippets Groups Projects
Commit c7c4b3d2 authored by Grayswandir's avatar Grayswandir
Browse files

Let table.check selectively not recurse.

parent e218ace7
No related branches found
No related tags found
No related merge requests found
......@@ -263,20 +263,21 @@ function table.removeFromList(t, ...)
end
end
function table.check(t, fct, path)
if path then path = path..'/' else path = '' end
function table.check(t, fct, do_recurse, path)
if path and path ~= '' then path = path..'/' else path = '' end
do_recurse = do_recurse or function() return true end
for k, e in pairs(t) do
local tk, te = type(k), type(e)
if te == "table" and not e.__CLASSNAME then
local ok, err = table.check(e, fct, path..tostring(k))
if te == "table" and not e.__CLASSNAME and do_recurse(e) then
local ok, err = table.check(e, fct, do_recurse, path..tostring(k))
if not ok then return nil, err end
else
local ok, err = fct(t, path..tostring(k), e, te)
if not ok then return nil, err end
end
if tk == "table" and not k.__CLASSNAME then
local ok, err = table.check(k, fct, path..tostring(k))
if tk == "table" and not k.__CLASSNAME and do_recurse(k) then
local ok, err = table.check(k, fct, do_recurse, path..tostring(k))
if not ok then return nil, err end
else
local ok, err = fct(t, path.."<key>", k, tk)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment