Skip to content

Table filter options

Table filters define what types of Luau tables should be returned when using filtergc with "table" as the filter type.

Each key in the filter table specifies a condition the table must meet in order to be returned. You can use one or multiple fields together to narrow your results.


Available Options

Key Type Description Default
Keys { any }? If provided, also includes tables that contain all the specified keys. nil
Values { any }? If provided, only includes tables that contain all the specified values. nil
KeyValuePairs { [any]: any }? If provided, only includes tables that contain all key-value pairs in this table. nil
Metatable table? If provided, only includes tables whose metatable matches the given one. nil

Notes

  • These filters work based on narrowing - the more information you provide in the filters, the more accurate the result.
  • If Metatable is used, a raw metatable comparison is performed.

Examples

False negatives may occur

Executing these examples multiple times in a short period of time may result in false negatives.

Matching by Keys

Matching a table by key
1
2
3
4
5
6
7
local dummy_table = { ["dummy_key"] = "" }

local retrieved = filtergc("table", {
    Keys = { "dummy_key" },
}, true)

print(retrieved == dummy_table) -- Output: true

Matching by KeyValuePairs

Matching a table by key-value pairs
1
2
3
4
5
6
7
local dummy_table = { ["dummy_key"] = "dummy_value" }

local retrieved = filtergc("table", {
    KeyValuePairs = { ["dummy_key"] = "dummy_value" },
}, true)

print(retrieved == dummy_table) -- Output: true

Matching by Metatable

Matching a table by metatable
1
2
3
4
5
6
7
local dummy_table = setmetatable({}, { __index = getgenv() })

local retrieved = filtergc("table", { 
    Metatable = getmetatable(dummy_table) 
}, true)

print(retrieved == dummy_table) -- Output: true