debug.setconstant
Changes a function constant.
Syntax
Signature
debug.setconstant(FunctionOrLevel: function | number, Index: number, Value: any) -> ()Aliases
This function has no aliases.
Parameters
| Parameter | Type | Description |
|---|---|---|
FunctionOrLevel | function | number | Luau closure or positive stack level. |
Index | number | One-based constant slot. |
Value | any | Replacement with the same type as the existing constant. |
Returns
| Type | Description |
|---|---|
() | None. |
Notes
The replacement must have the same VM type as the old value. Table and function constants, and replacements with another type, are left unchanged. An invalid index raises an error.
Example
Luau
local Function = function() return "before" end
for Index, Value in debug.getconstants(Function) do
if Value == "before" then
debug.setconstant(Function, Index, "after")
end
end
print(Function())