Advertisement
Guest User

Untitled

a guest
Sep 20th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. TableUtils = {};
  2.  
  3. function TableUtils.clone(org)
  4.   local new = {};
  5.   for k, v in pairs(org) do
  6.     new[k] = v;
  7.   end
  8.   return new;
  9. end
  10.  
  11. function TableUtils.findEntries(db, searchInfo, copy)
  12.   local out = {}
  13.  
  14.   for k, v in pairs(db) do
  15.     local add = false;
  16.     for k2, v2 in pairs(v) do
  17.       if searchInfo[k2] then
  18.         local c = false;
  19.         if searchInfo[k2].type == "exact" then
  20.           if searchInfo[k2].value == v2 then
  21.             c = true;
  22.           end
  23.         elseif searchInfo[k2].type == "pattern" then
  24.           if tostring(v2):find(searchInfo[k2].value) then
  25.             c = true;
  26.           end
  27.         end
  28.  
  29.         if not c then
  30.           if searchInfo[k2].mandatory then
  31.             add = false;
  32.             break;
  33.           end
  34.         else
  35.           add = true;
  36.         end
  37.       end
  38.     end
  39.  
  40.     if add then
  41.       if copy then
  42.         out[k] = TableUtils.clone(v);
  43.       else
  44.         out[k] = v;
  45.       end
  46.     end
  47.   end
  48.  
  49.   return out;
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement