Skip to content

Function filter options

Function filters let you refine what types of Luau functions should be returned when using filtergc with "function" as the filter type.

Each key in the filter table specifies a criterion that must be matched by the function for it to be returned. You can use one or multiple fields together to narrow your results.


Available options

Key Type Description Default
Name string? If provided, filters out functions which don't match this name. nil
IgnoreExecutor boolean? If true, filters out functions that were created inside the executor. true
Hash string? Filters by the hash of the function. See getfunctionhash. nil
Constants { any }? Also includes functions that contain the matching constants in the provided list. nil
Upvalues { any }? Also includes functions that contain the matching upvalues in the provided list. nil

Notes

  • These filters work based on narrowing - the more information you provide in the filters, the more accurate the final result.
  • If IgnoreExecutor is not explicitly set to false, executor-created functions are skipped by default.
  • Filters like Constants, Upvalues, and Hash do not apply to C closures.

Examples

False negatives may occur

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

Using Name (returns a table by default)

Matching a function by name
1
2
3
4
5
6
7
8
9
local function dummy_function() end

local retrieved = filtergc("function", {
    Name = "dummy_function", 
    IgnoreExecutor = false
})

print(typeof(retrieved)) -- Output: table
print(retrieved[1] == dummy_function) -- Output: true

Using Name with returnOne = true

Single match using returnOne
local function dummy_function() 
end

local retrieved = filtergc("function", {
    Name = "dummy_function", 
    IgnoreExecutor = false
}, true)

print(typeof(retrieved)) -- Output: function
print(retrieved == dummy_function) -- Output: true

Using Hash

Matching a function by hash
local function dummy_function()
    return "Hello"
end

local dummy_function_hash = getfunctionhash(dummy_function)

local retrieved = filtergc("function", {
    Hash = dummy_function_hash,
    IgnoreExecutor = false
}, true)

print(getfunctionhash(retrieved) == dummy_functionHash) -- Output: true
print(retrieved == dummy_function) -- Output: true

Matching by Constants and Upvalues

Matching by function constants and upvalues
local upvalue = 5

local function dummy_function()
    upvalue += 1
    print(game.Players.LocalPlayer)
end

local retrieved = filtergc("function", {
    Constants = { "print", "game", "Players", "LocalPlayer", 1 },
    Upvalues = { 5 },
    IgnoreExecutor = false
}, true)

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