Skip to content
Debug libraryOverview

debug.setconstant

Represents modification of a function constant.

Aliasessetconstant

Details#

Replaces a constant at a one-based index only when the replacement has the existing constant's type. Table/function constants and type mismatches are left unchanged. Invalid indices raise an error; returns no values.

Examples#

Example

Luau
local f = assert(loadstring("return 'before'"))
for index, value in pairs(debug.getconstants(f)) do
    if value == "before" then debug.setconstant(f, index, "after") end
end
print(f()) -- after