Functions & closuresReferenceNew · 0.744
hookproto
Describe function interception through the prototype-oriented API.
Details#
Intercepts the supplied Luau closure using function-hook semantics. A proto is the compiled description of a Luau function; a closure combines that code with captured values. This API takes a function value, not a parent function plus a nested-prototype index. C closures and targets already hooked through this mechanism raise an error. It does not promise to replace every closure sharing the same prototype.
Signature#
hookproto(target: function, replacement: function): functionParameters#
| Parameter | Type | Description |
|---|---|---|
target | function | The exact function value to inspect or modify. |
replacement | function | Replacement callable, receiving the target's arguments. |
Returns#
The previous implementation of target.
Examples#
Example
local function calculate(n) return n + 1 end
local original = hookproto(calculate, function(n) return n + 10 end)
print(calculate(5)) -- 15
print(original(5)) -- 6
restoreproto(calculate)
print(calculate(5)) -- 6