ForeverDev

Untitled

Oct 17th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.30 KB | None | 0 0
  1. local object = {}
  2. local select = ""
  3.  
  4. local callback = function() end --catch the error of 'callback is a nil value'
  5.  
  6. local getBy = function(parent, check, by, extra)
  7.     local iterate;
  8.     iterate = function(parent, check, by, extra)
  9.         for index, value in pairs(parent:GetChildren()) do
  10.             if by == "class" then
  11.                 if value.ClassName:lower() == check:lower() then
  12.                     table.insert(object, value)
  13.                 end
  14.             elseif by == "name" then
  15.                 if value.Name:lower() == check:lower() then
  16.                     table.insert(object, value)
  17.                 end
  18.             elseif by == "property" then
  19.                 if pcall(function() return value[check] end) then
  20.                     local kind = type(value[check])
  21.                     if value[check] == (kind == "string" and tostring(extra) or kind == "number" and tonumber(extra) or extra) then
  22.                         table.insert(object, value)
  23.                     end
  24.                 end
  25.             elseif by == "all" then
  26.                 table.insert(object, value)
  27.             end
  28.             iterate(value, check, by, extra)
  29.         end
  30.     end
  31.     iterate(parent, check, by, extra)
  32. end
  33.  
  34. local loop = function(lqCallback, userCallback, ...)
  35.     for index, value in pairs(object) do
  36.         if lqCallback then
  37.             lqCallback(index, value)
  38.         end
  39.         if userCallback then
  40.             userCallback(index, value, ...)
  41.         end
  42.     end
  43.     return lq
  44. end
  45.  
  46. local removeElement = function(array, element)
  47.     for index, value in ipairs(array) do
  48.         if value == element then
  49.             table.remove(array, index)
  50.         end
  51.     end
  52. end
  53.  
  54. local warn = function(warning, selector)
  55.     return "WARNING: " .. warning .. " ( " .. selector .. " ) "
  56. end
  57.  
  58. local lq;
  59. lq = {
  60.     each = function(callback)
  61.         return loop(nil, callback)
  62.     end,
  63.     dest = function(callback)
  64.         return loop(function(_, value) value:Destroy() end, callback)
  65.     end,
  66.     val = function(key)
  67.         if not key and #object == 1 and object[1]:FindFirstChild("LQ_SAVE_KEY") then
  68.             return object[1]["LQ_SAVE_KEY"].Value
  69.         elseif not key then
  70.             return warn("Cannot get the value of multiple items!", select)
  71.         end
  72.         return loop(function(_, value)
  73.             if value:FindFirstChild("LQ_SAVE_KEY") then
  74.                 value["LQ_SAVE_KEY"].Value = key
  75.             else
  76.                 local save = Instance.new("StringValue", value)
  77.                 save.Name = "LQ_SAVE_KEY"
  78.                 save.Value = key
  79.             end
  80.         end)
  81.     end,
  82.     color = function(color)
  83.         local colors = {
  84.             blue = "Bright blue",
  85.             red = "Bright red",
  86.             green = "Bright green",
  87.             orange = "Bright orange",
  88.             yellow = "Bright yellow",
  89.             purple = "Bright purple",
  90.             white = "White",
  91.             black = "Black"
  92.         }
  93.         return loop(function(_, value)
  94.             if value:IsA("BasePart") then
  95.                 value.BrickColor = BrickColor.new(colors[color:lower()] or color)
  96.             end
  97.         end)
  98.     end,
  99.     attr = function(property, set)
  100.         if type(property) == "table" then
  101.             return loop(function(_, value)
  102.                 for property, apply in pairs(property) do
  103.                     pcall(function() value[property] = apply end)
  104.                 end
  105.             end)
  106.         elseif set then
  107.             return loop(function(_, value)
  108.                 pcall(function() value[property] = set end)
  109.             end)
  110.         elseif pcall(function() return object[1][property] and not object[1]:FindFirstChild(property) end) then
  111.             return object[1][property]
  112.         end
  113.     end,
  114.     listen = function(event, callback)
  115.         local events = {
  116.             change = "Changed", newplayer = "PlayerAdded"
  117.         }
  118.         return loop(function(_, value)
  119.             pcall(function() value[events[event:lower()] or event]:connect(callback) end)
  120.         end)
  121.     end,
  122.     rand = function()
  123.         return object[math.random(#object)]
  124.     end,
  125.     indexOf = function(search)
  126.         local ret = false
  127.         if type(object) == "string" then
  128.             ret = object:find(search)
  129.         else
  130.             loop(function(index, value)
  131.                 if value == search then
  132.                     ret = index
  133.                 end
  134.             end)
  135.         end
  136.         return ret
  137.     end,
  138.     insert = function(...)
  139.         for _, value in ipairs({...}) do
  140.             table.insert(object, value)
  141.         end
  142.         return lq
  143.     end,
  144.     rid = function(...)
  145.         for index, value in ipairs(object) do
  146.             for _, check in ipairs({...}) do
  147.                 if check == value then
  148.                     table.remove(object, index)
  149.                 end
  150.             end
  151.         end
  152.         return lq
  153.     end,
  154.     concat = function(split)
  155.         return table.concat(object, split)
  156.     end,
  157.     greatest = function()
  158.         return math.max(unpack(object))
  159.     end,
  160.     least = function()
  161.         return math.min(unpack(object))
  162.     end,
  163.     raw = function()
  164.         return object
  165.     end
  166. }
  167.  
  168. local ret = function(selector, parent)
  169.     object = {}
  170.     select = selector
  171.     parent = parent or Workspace
  172.     if type(selector) == "string" then
  173.         local matched;
  174.         selector:gsub("%.(.-)/", function(pattern)
  175.             matched = true
  176.             getBy(parent, pattern, "class")
  177.         end):gsub("#(.-)/", function(pattern)
  178.             matched = true
  179.             getBy(parent, pattern, "name")
  180.         end):gsub("%?([%a%d]+)=(.-)/", function(patternOne, patternTwo)
  181.             matched = true
  182.             getBy(parent, patternOne, "property", patternTwo)
  183.         end):gsub("&(.-)/", function(pattern)
  184.             matched = true
  185.             if pattern:lower() == "direct" then
  186.                 for _, v in ipairs(parent:GetChildren()) do
  187.                     table.insert(object, v)
  188.                 end
  189.             elseif pattern:lower() == "all" then
  190.                 getBy(parent, nil, "all")
  191.             end
  192.         end):gsub("%?([%a%d]+)!=(.-)/", function(patternOne, patternTwo)
  193.             matched = true
  194.             for _, v in pairs(object) do
  195.                 pcall(function()
  196.                     if v[patternOne] == patternTwo then
  197.                         removeElement(object, v)
  198.                     end
  199.                 end)
  200.             end
  201.         end)
  202.         if not matched then
  203.             object = selector
  204.         end
  205.     elseif type(selector) == "table" then
  206.         object = selector
  207.     else
  208.         object = {selector}
  209.     end
  210.     return lq
  211. end
  212.  
  213. return ret
Advertisement
Add Comment
Please, Sign In to add comment