Replaces the constant in slot index with value. Every closure sharing that prototype sees the change, because constants live on the prototype rather than the closure.
Every function on this page is reachable both as debug.<name> and as a plain global of the same name, so debug.getupvalues(f) and getupvalues(f) are the same call.

Parameters

function | number
required
The function to inspect, or a stack level. Level 1 is your caller.
number
required
The constant slot to write.
any
required
The replacement. Its type must match the constant already in the slot.

Behavior

  • The type must match. You can swap a string for a string or a number for a number, but not a string for a number. This is deliberate: the compiler emitted instructions that assume the slot’s type.
  • Table and function slots cannot be written at all.
  • It affects every closure on that prototype, including ones already created.

Example

Errors