AcediaDocumentation

debug.setconstant

Replaces a Lua constant without changing its value type.

Closures sharing the prototype can observe the change.

debug.setconstant(subject: function | number, index: number, value: any): ()

Parameters

ParameterTypeDescription
subjectfunction | numberLua function or reachable stack level. C functions are rejected by prototype readers.
indexnumberOne-based constant index.
valueanyReplacement with the same Luau type as the existing constant.

Example

local function sample() return "before" end
for index, value in pairs(debug.getconstants(sample)) do
    if value == "before" then debug.setconstant(sample, index, "after") end
end
print(sample())

Example output

after

Errors: Out-of-range indices and replacement type mismatches raise errors.

Aliases: setconstant.

On this page