debug. setproto Synchronous
Replace one nested prototype reference in a Luau function. It affects closures created from that nested slot after the change, so retain a matching original closure if you plan to restore it.
Luau
debug.setproto(target: Function | number, index: number, replacement: Function) -> ()Parameters
| Parameter | Type | Description |
|---|---|---|
target | Function | number | Luau function or visible stack level containing the nested prototype. |
index | number | One-based child prototype slot. |
replacement | Function | Luau function with the required upvalue count. |
Returns
()No value.
Usage notes
Replacement upvalue count must match the target prototype’s upvalue count.
Example
Luau
local function factory() return function() return "before" end end
local original = factory()
debug.setproto(factory, 1, function() return "after" end)
print(factory()()) -- after
debug.setproto(factory, 1, original)