Returns a new function. When it is called, 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

Filter
required
Any filter object.
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, nil holes, 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 original or hook can call task.wait and similar.
  • Errors propagate. An error raised inside hook or original reaches the caller unchanged.
  • The result is an executor closure. isexecutorclosure reports true for it.

Example

Errors