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
| Parameter | Type | Description |
|---|---|---|
subject | function | number | Lua function or reachable stack level. C functions are rejected by prototype readers. |
index | number | One-based constant index. |
value | any | Replacement 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
afterErrors: Out-of-range indices and replacement type mismatches raise errors.
Aliases: setconstant.
