hookproto Synchronous
Replace a nested Luau prototype so calls to closures created from it use replacement code. Use this for a specific nested function obtained with debug.getproto, and restore it after the inspection or experiment.
Luau
hookproto(target: ProtoProxy, replacement: Function) -> ()Parameters
| Parameter | Type | Description |
|---|---|---|
target | ProtoProxy | ProtoProxy returned by debug.getproto or debug.getprotos. |
replacement | Function | Luau function with no captured upvalues. |
Returns
()No value.
Usage notes
The target prototype must also have no upvalues. A later hookproto on the same target replaces the earlier proto hook.
Example
Luau
local function factory()
return function() return "before" end
end
local proto = debug.getproto(factory, 1)
hookproto(proto, function() return "after" end)
print(factory()()) -- after
restoreproto(proto)