filter is evaluated against the
arguments: on a match the call is forwarded to hook, otherwise to original.
Both receive the arguments unchanged, and whatever they return is returned to the
caller.
This is the standalone form of the filter argument on
hookfunction and
hookmetamethod. Use it when you want the routing
behavior without installing a hook anywhere.
Parameters
function
required
Called when the filter does not match.
function
required
Called when the filter matches.
Returns
function
A function that dispatches to
hook or original per call.Behavior
- Arguments and returns pass through. Varargs,
nilholes, and multiple return values are preserved in both directions. - The filter runs natively. Matching happens in C++ before either function is entered.
- Either side may yield. The routed function is yield-safe, so
originalorhookcan calltask.waitand similar. - Errors propagate. An error raised inside
hookororiginalreaches the caller unchanged. - The result is an executor closure.
isexecutorclosurereportstruefor it.
Example
Errors
Related
- Filter: the filter classes.
hookfunction/hookmetamethod: take a filter directly.