Skip to content
DiagnosticsReferenceNew · 0.744

registercallback

Store a named local callback in the diagnostics registry.

Details#

Keeps a function reference under the supplied name. Registering the same name again replaces the previous reference. This operation stores the function; it does not invoke it or attach it to an event.

Signature#

Luau
registercallback(name: string, callback: function): boolean

Parameters#

ParameterTypeDescription
namestringRegistry key. Use a plain name without embedded NUL bytes.
callbackfunctionFunction reference to retain until replacement or removal.

Returns#

true after registration. A missing name or a non-function second argument raises an argument error.

Examples#

Register and release a callback without running it

Luau
local called = false
assert(registercallback("docs.local-example", function()
    called = true
end))
assert(called == false) -- registration does not call the function
assert(unregistercallback("docs.local-example"))

Notes#

  • Registering a callback does not run it. Remove unused callbacks with unregistercallback.