oth. hook Synchronous
Add a hook layer to a C closure. Its optional filter selects which calls reach this layer; misses continue to earlier layers or the original.
Luau
oth.hook(target: Function, callback: Function, filter: HookFilter?) -> FunctionParameters
| Parameter | Type | Description |
|---|---|---|
target | Function | C closure to hook. Luau closures are rejected. |
callback | Function | Luau closure to run on matching calls. C closures are rejected as callbacks. |
filter | HookFilter? | Optional HookFilter that applies only to this newly installed layer. |
Returns
FunctionA callable for the preceding layer. Call it inside the callback to forward the current arguments and results.
Usage notes
Each OTH callback runs on a hook thread. Newer layers are checked first; a filter miss falls through to the preceding layer.
Save the returned callable so oth.unhook can identify this registration when several layers exist. Use oth.get_root_callback inside a callback to bypass the full chain.
Example
Luau
local target = newcclosure(function(value) return value * 2 end)
local previous
previous = oth.hook(target, function(value)
return previous(value) + 1
end, ArgumentFilter.new(1, 3))
print(target(3)) -- 7
print(target(4)) -- 8
oth.unhook(target, previous)