Yuari
Documentation
Docs/Filter

Filter

Filter objects decide which calls reach a hook or a routed replacement. Each constructor returns a filter value that can be inspected with typeof or tostring, combined with other filters, and passed to getfilter. Filters are evaluated when the wrapped function runs, not when they are created.

Hooks. hookfunction accepts an optional third argument: a filter. Matching calls reach the replacement, while other calls reach the original behavior.

Creates a filter that matches when every child filter matches. An empty filter list always matches.

local named = InstanceNameFilter.new(1, "Part")
local typed = InstanceTypeFilter.new(1, "BasePart")
local filter = AllFilter.new({ named, typed })
print(filter) -- AllFilter

Creates a filter that matches when any child filter matches. An empty filter list never matches.

local stringOrNumber = AnyFilter.new({
    TypeFilter.new(1, "string"),
    TypeFilter.new(1, "number")
})
print(stringOrNumber) -- AnyFilter

Creates a filter that checks the number of arguments passed to the routed call.

local twoArguments = ArgCountFilter.new(2)
print(twoArguments) -- ArgCountFilter

Creates a filter that compares the argument at a one-based position with a stored value.

local wantsHello = ArgumentFilter.new(1, "hello")
print(wantsHello) -- ArgumentFilter

Creates a filter that checks whether the caller is an executor closure. Pass true to match game callers instead.

local fromExecutor = CallerFilter.new(false)
local fromGame = CallerFilter.new(true)
print(fromExecutor, fromGame) -- CallerFilter CallerFilter

Creates a function that routes matching calls to filtered and all other calls to original. Both branches receive the original arguments, and yields pass through the routed function.

local routed = getfilter(
    TypeFilter.new(1, "string"),
    function(value) return "original: " .. tostring(value) end,
    function(value) return "filtered: " .. value end
)
print(routed("hello")) -- filtered: hello
print(routed(10)) -- original: 10

Creates a filter that checks the Name of an Instance argument against an exact string.

local wantsRoot = InstanceNameFilter.new(1, "HumanoidRootPart")
print(wantsRoot) -- InstanceNameFilter

Creates a filter that checks an Instance argument with Instance:IsA, so base classes such as BasePart are accepted.

local wantsPart = InstanceTypeFilter.new(1, "BasePart")
print(wantsPart) -- InstanceTypeFilter

Creates a filter that checks the active namecall method, such as HttpGet or FindFirstChild.

local httpGetOnly = NamecallFilter.new("HttpGet")
local original = hookfunction(game.HttpGet, function(self, url)
    return "blocked"
end, httpGetOnly)

Creates a filter that reverses the result of another filter.

local notString = NotFilter.new(TypeFilter.new(1, "string"))
print(notString) -- NotFilter

Creates a filter that checks the Luau type name of an argument, including userdata type names reported by typeof.

local wantsNumber = TypeFilter.new(1, "number")
local routed = getfilter(wantsNumber,
    function(value) return "other" end,
    function(value) return value * 2 end
)
print(routed(21)) -- 42

Creates a filter that checks a userdata argument's type using an exemplar value, so Vector3 arguments match Vector3 and CFrame arguments match CFrame.

local wantsVector = UserdataTypeFilter.new(1, Vector3.new())
print(wantsVector) -- UserdataTypeFilter