ArgumentFilter. new Synchronous
Match a call when one argument equals an expected value. Use it to limit a hook to calls with a known marker, receiver, or other argument.
Luau
ArgumentFilter.new(index: number, expected: any?) -> HookFilterParameters
| Parameter | Type | Description |
|---|---|---|
index | number | One-based positive integer argument position. Index 1 is the first argument visible to the hooked function; for methods this is usually the receiver. |
expected | any? | Value to compare with the argument. Omitted or nil also matches a missing argument at this position. |
Returns
HookFilterA HookFilter table to pass as the optional filter argument of hookfunction, hookmetamethod, or oth.hook. It does not run until a hooked call is evaluated.
Usage notes
Strings and numbers compare by value. Tables and most other objects compare by identity; Roblox Instances compare by their underlying Instance identity.
A match calls the replacement. A miss continues through the preceding hook or original function. Omit the filter or pass nil to handle every call.
Example
Luau
local target = newcclosure(function(value) return value end)
local onlyReady = ArgumentFilter.new(1, "ready")
local previous
previous = hookfunction(target, function(value)
return "matched: " .. previous(value)
end, onlyReady)
print(target("ready")) -- matched: ready
print(target("wait")) -- wait
restorefunction(target)