AcediaDocumentation

hookfunction

Replaces a function's behavior and returns a callable copy of its previous behavior.

Retain the returned original to call the pre-hook implementation. Certain executor namecall wrapper targets are protected and return nil.

hookfunction(target: function, replacement: function): function?

Parameters

ParameterTypeDescription
targetfunctionFunction whose calls will be redirected.
replacementfunctionNew implementation.

Example

local function target(value) return value + 1 end
local original = hookfunction(target, function(value) return value + 10 end)
print(target(1), original(1))
restorefunction(target)

Example output

11	2

Aliases: replaceclosure, hookfunc.

On this page