Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TableUtils = {};
- function TableUtils.clone(org)
- local new = {};
- for k, v in pairs(org) do
- new[k] = v;
- end
- return new;
- end
- function TableUtils.findEntries(db, searchInfo, copy)
- local out = {}
- for k, v in pairs(db) do
- local add = false;
- for k2, v2 in pairs(v) do
- if searchInfo[k2] then
- local c = false;
- if searchInfo[k2].type == "exact" then
- if searchInfo[k2].value == v2 then
- c = true;
- end
- elseif searchInfo[k2].type == "pattern" then
- if tostring(v2):find(searchInfo[k2].value) then
- c = true;
- end
- end
- if not c then
- if searchInfo[k2].mandatory then
- add = false;
- break;
- end
- else
- add = true;
- end
- end
- end
- if add then
- if copy then
- out[k] = TableUtils.clone(v);
- else
- out[k] = v;
- end
- end
- end
- return out;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement