Replaces upvalue index of target with value. Any type is accepted.
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 upvalue index to write.
any
required
The replacement. Unlike constants, the type does not have to match.

Behavior

  • Shared upvalues are shared. If several closures captured the same local, writing it through one of them changes it for all of them, exactly as the original code would.
  • Any type is allowed, because an upvalue is an ordinary variable slot.

Example

Errors