CallerFilter. new Synchronous
Match a call by where it originated. Use the default to handle executor-originated calls, or invert it when a hook should handle calls from game code instead.
Luau
CallerFilter.new(invert: boolean?) -> HookFilterParameters
| Parameter | Type | Description |
|---|---|---|
invert | boolean? | Optional boolean. Omitted, nil, or false matches executor callers; true matches game callers. |
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
The caller is checked when the hooked function runs, not when the filter is created or the hook is installed. A call made directly by your executor script will not match CallerFilter.new(true).
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() return "original" end)
local executorOnly = CallerFilter.new()
local previous
previous = hookfunction(target, function()
return "handled: " .. previous()
end, executorOnly)
print(target()) -- handled: original
restorefunction(target)
-- Pass CallerFilter.new(true) when installing a hook that should
-- run only for calls originating in game code.