Rewrites the debug information a Luau function reports about itself. This changes what tracebacks, error messages and getinfo say about it.
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 relabel, or a stack level.
table
required
A table of replacements. Recognised keys: source, short_src, name, linedefined. Anything else is ignored.

Behavior

  • source wins over short_src. Give source to set the chunk name exactly. Give short_src instead and the existing = or @ marker is kept on the front, so the chunk keeps its kind.
  • It edits the prototype, so every closure sharing it reports the new information.
  • Only the listed keys are read. Other debug fields are derived from the bytecode and cannot be rewritten this way.

Example

Errors