ArgCountFilter.new Synchronous

Match calls with exactly a given number of arguments. This is handy when an overloaded callback uses the number of supplied values to distinguish one form of a call from another.

Syntax
Luau
ArgCountFilter.new(count: number) -> HookFilter

Parameters

Function parameters
ParameterTypeDescription
countnumberExact number of arguments to match, as a nonnegative integer. Zero matches calls made with no arguments.

Returns

HookFilter

A 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

An explicit trailing nil counts as an argument; an omitted argument does not. A method receiver counts as an argument when it is passed to the hooked function.

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

Example
Luau
local target = newcclosure(function(...) return select("#", ...) end)
local exactlyTwo = ArgCountFilter.new(2)
local previous
previous = hookfunction(target, function(...)
    return previous(...) + 10
end, exactlyTwo)
print(target("ready", nil)) -- 12: the nil is still an argument
print(target("ready"))      -- 1: one argument, so the hook is skipped
restorefunction(target)
Kawaii documentation