Give it a number instead of a function and it targets the closure running at that stack level.
Parameters
Returns
void
Aliases
setupvalue
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
debug.setupvalue(func: function | number, index: number, value: any): ()
| Parameter | Type | Description |
|---|---|---|
func | function | number | The closure to change, or a stack level pointing at one. |
index | number | Which upvalue to overwrite. |
value | any | What to store in the slot. |
void
setupvaluedebug.setupvalue(function(...) end, 1, "test")
local count = 0
local function ping()
count += 1 -- count is reassigned here, so it stays a real upvalue and isn't inlined
print(`ping #{count}`)
end
ping() -- ping #1
debug.setupvalue(ping, 1, 41)
ping() -- ping #42