Closures

hookfunction

Replaces a target function with a replacement and returns the original function.

Syntax

hookfunction(target: function, replacement: function): function
Aliases hookfuncreplaceclosuredetourfunctiondetour_function

Arguments

NameTypeDescription
targetfunctionTarget function, table, stack level, or object being inspected or changed.
replacementfunctionReplacement value or function that should be installed.

Returns

NameTypeDescription
originalfunctionOriginal function before it was replaced.

Description

Replaces a target function with a replacement and returns the original function.

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

Example call with placeholder values.

local result = hookfunction(function() end, function() end)
print(result)