Syntax
hookfunction(target: function, replacement: function): functionAliases
hookfuncreplaceclosuredetourfunctiondetour_functionArguments
| Name | Type | Description |
|---|---|---|
target | function | Function to patch. Passing a non-function raises a type error. |
replacement | function | Function whose function is installed into or mapped onto target. Passing a non-function raises a type error. |
Returns
| Name | Type | Description |
|---|---|---|
original | function | Callable copy of the original target behavior before the hook was installed. |
Description
Replaces the behavior of a target function with a replacement function and returns a callable copy of the original behavior. Both arguments must be functions.
Call it with 2 parameter(s): target, replacement. The argument table explains which values are required and which ones only refine the behavior.
It returns original (function). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Patch a function closure and keep a cloned original.
local function target(value)
return value + 1
end
local original
original = hookfunction(target, function(value)
return original(value) * 2
end)