FilterBase

Construct and combine the current module function filters.

11 functionssUNC 100%Lynx 0.0.0

Filters are module-created tables with validated properties and a protected FilterBase metatable. FilterBase itself is an empty namespace with no public constructor. Build a concrete filter using one of the .new functions below, combine it, then pass it to hookfunction/hookmetamethod or getfilter.

Argument indices are positive and 1-based; an implicit method receiver counts as argument 1. Out-of-range indexed arguments do not match. Evaluation short-circuits All/Any lists, rejects cycles, and raises an error beyond 64 levels or 4096 visited nodes.

AllFilter.new

AllFilter.new(filters: {FilterBase}? = {}): FilterBase

Matches only when every child filter matches. An empty list matches.

Parameters

filters{FilterBase}?
Optional.Sequential child filter list. Default {}.

Returns

FilterBase

Concrete filter table with properties: Filters: {FilterBase}.

Example

local f = AllFilter.new({ TypeFilter.new(1, "string"), ArgCountFilter.new(1) })

AnyFilter.new

AnyFilter.new(filters: {FilterBase}? = {}): FilterBase

Matches when any child filter matches. An empty list does not match.

Parameters

filters{FilterBase}?
Optional.Sequential child filter list. Default {}.

Returns

FilterBase

Concrete filter table with properties: Filters: {FilterBase}.

Example

local f = AnyFilter.new({ TypeFilter.new(1, "string"), TypeFilter.new(1, "number") })

NotFilter.new

NotFilter.new(target: FilterBase): FilterBase

Negates a child filter. An invalid nested filter does not become a successful match.

Parameters

targetFilterBase
Child filter to negate.

Returns

FilterBase

Concrete filter table with properties: Target: FilterBase.

Example

local f = NotFilter.new(TypeFilter.new(1, "nil"))

TypeFilter.new

TypeFilter.new(index: number, argumentType: string): FilterBase

Compares the base Luau type name of an argument, not Roblox typeof. For example an Instance is userdata here.

Parameters

indexnumber
Positive argument index.
argumentTypestring
Base type name, such as string, number, table or userdata.

Returns

FilterBase

Concrete filter table with properties: ArgumentIndex: number; ArgumentType: string.

Example

local f = TypeFilter.new(1, "string")

NamecallFilter.new

NamecallFilter.new(method: string): FilterBase

Compares the current thread namecall method using an exact case-sensitive byte comparison.

Parameters

methodstring
Namecall method name.

Returns

FilterBase

Concrete filter table with properties: NamecallMethod: string.

Example

local f = NamecallFilter.new("GetService")

InstanceTypeFilter.new

InstanceTypeFilter.new(index: number, className: string): FilterBase

Matches an Instance argument using the native IsA class relation, so inherited classes match too.

Parameters

indexnumber
Positive argument index.
classNamestring
Native class name, such as BasePart.

Returns

FilterBase

Concrete filter table with properties: ArgumentIndex: number; InstanceType: string.

Example

local f = InstanceTypeFilter.new(1, "BasePart")

ArgumentFilter.new

ArgumentFilter.new(index: number, argument: any): FilterBase

Matches one argument by raw equality. Tables/functions match by identity. StripNull defaults to false; when enabled for two strings, comparison truncates each at its first NUL byte.

Parameters

indexnumber
Positive argument index.
argumentany
Value to match, including nil.

Returns

FilterBase

Concrete filter table with properties: ArgumentIndex: number; Argument: any; StripNull: boolean = false.

Example

local f = ArgumentFilter.new(1, "hello")
f.StripNull = true

UserdataTypeFilter.new

UserdataTypeFilter.new(index: number, exemplar: userdata): FilterBase

Matches userdata with the same native tag and metatable as an exemplar. The UserdataType property is write-only and stores the exemplar userdata, not a type-name string.

Parameters

indexnumber
Positive argument index.
exemplaruserdata
Value representing the desired userdata kind.

Returns

FilterBase

Concrete filter table with properties: ArgumentIndex: number; UserdataType: userdata (write-only).

Example

local f = UserdataTypeFilter.new(1, game)

ArgCountFilter.new

ArgCountFilter.new(count: number): FilterBase

Matches exactly the number of arguments delivered to the filtered call, including nil arguments and an explicit receiver.

Parameters

countnumber
Nonnegative exact argument count.

Returns

FilterBase

Concrete filter table with properties: ArgumentCount: number.

Example

local f = ArgCountFilter.new(2)

CallerFilter.new

CallerFilter.new(invert: boolean): FilterBase

Matches module-marked calling threads when invert is false, or unmarked calling threads when invert is true.

Parameters

invertboolean
Whether to invert the module thread-mark test.

Returns

FilterBase

Concrete filter table with properties: Invert: boolean.

Example

local f = CallerFilter.new(false)

getfilter

getfilter(filter: FilterBase, fallback: function, matched: function): function

Creates a yield-capable dispatcher. Each call evaluates the filter against its original argument list, then calls matched when it succeeds or fallback when it does not. Arguments and all return values are forwarded.

Parameters

filterFilterBase
Concrete module filter object.
fallbackfunction
Callback for a nonmatching or invalid filter result.
matchedfunction
Callback for a successful match.

Returns

function

C dispatcher retaining the filter and both callbacks.

Example

local choose = getfilter(TypeFilter.new(1, "number"),
function(value) return "other", value end,
function(value) return "number", value end)
print(choose(42))
print(choose("hello"))