hookfunction
Replaces a function's behavior.
Syntax
Signature
hookfunction(Target: function, Replacement: function) -> functionAliases
replaceclosurehookfunc
Parameters
| Parameter | Type | Description |
|---|---|---|
Target | function | Original function to inspect or replace. |
Replacement | function | Function used instead of the target. |
Returns
| Type | Description |
|---|---|
function | Callable copy of the target's behavior before this hook. |
Notes
Returns a separate function for Target's behavior before this call. Hooking the same target again changes its replacement. restorefunction restores the behavior saved by the first hook.
Example
Luau
local Function = function() return "original" end
local Original = hookfunction(Function, function() return "hooked" end)
print(Function(), Original())
restorefunction(Function)