A Lua/Roblox function made to filter and deep search values inside a table blazingly fast, with custom filter options and a "Next Scan" method, making filtering dynamic/specific values way easier.
filterOptions= {
type=<luatype>searchesforthespecificgiventypefirstMatchOnly=<bool>whetherornotonlythefirstmatchedvaluewillbereturnedlogPath=<bool>logsthepathtakenbythefilterTable, maydecreaseperformancedeepSearch=<bool>searcheseveryfunctionconstants, upvalues, protosandenv (willdecreaseperformance)
validator=<<bool>function(i,v)>validatesanentryusingafunction**willoverridethedefaultchecking, sousinganyoptionspresentedbelowwillnotwork**
}
extrafilterOptionsforspecifictypes:
function->name=<functionname>upvalues=<exactupvaluestableoffunction>constants=<exactconstantstableoffunction>protos=<exactprotostableoffunction>matchUpvalues=<tablewithrequiredupvaluesoffunction>matchConstants=<tablewithrequiredconstantsoffunction>matchProtos=<tablewithrequiredprotosoffunction>upvalueAmount=<upvalueamountoffunction>constantAmount=<constantamountoffunction>protoAmount=<protoamountoffunction>info=<exactdebug.infotableoffunction>matchInfo=<tablewithrequireddebug.infooffunction>ignoreEnv=<bool>script=<Instance<script>>**onlyforfunctionswith"script"definedintheirenv**table->tableMatch= {index=<tableindex>, value=<tablevalue>, validator=<validator>}
tableSize=<sizeoftable>metatable=<exactmetatableoftable>hasMetatable=<bool>userdata->metatable=<exactmetatableoftable>hasMetatable=<bool>
[robloxtype] ->className=<string>property=<<string>robloxpropertyname>forcheckingpropertiesofobjects, e.gcheckingtheCFramepropertyofBasePart's->{type="Instance", classname="BasePart", property="CFrame", value=CFrame.new()}returnformat= {
{
Value,
Index,
Parent,
SearchId,
(additionalvalues)
},
(...)
}localtbl= {"testing", {"testing"}}
localresults=filterTable(tbl, {type="string", value="testing"})
fori,vinpairs(results) do-- you can also use results.print() instead of thistable.foreach(v, print)
-- expected output:--[[ Index 1 Value testing Parent table: 0x0000000000000000 (this is equivalent to tbl) SearchId a7HS (random) Index 1 Value testing Parent table: 0x0000000000000001 (this is equivalent to tbl[2]) SearchId a7HS (random)]]endlocaltbl= {"testing", {"testing"}}
localresults=filterTable(tbl, {type="string", value="testing"}) -- will return 2 valuestbl[1] ="not testing" -- change one of the valuesresults=results.nextScan({type="string", value="testing"}) -- will return only 1 value (the unchanged one)fori,vinpairs(results) dotable.foreach(v, print)
-- expected output:--[[ Index 1 Value testing Parent table: 0x0000000000000001 (this is equivalent to tbl[2]) SearchId 65CA (random)]]endExample usage on a roblox game (searching every single lua object in the garbage collector with deepSearch in 0.03s)
04b14f521b398d1a942769b7a3a2b468.mp4
Instead of looping through results and printing each results table manually you can use the display(limit) method appended to every result of filterTable.
limit is the max amount of results to be displayed, if its nil, it will print every entry
localtbl= {"testing", {"testing"}}
localresults=filterTable(tbl, {type="string", value="testing"})
results.display()
-- expected output:--[[filterTable (result #1)Index 1Value testingParent table: 0x0000000000000000 (this is equivalent to tbl)SearchId klF1 (random)filterTable (result #2)Index 1Value testingParent table: 0x0000000000000001 (this is equivalent to tbl[2])SearchId klF1 (random)]]