newcclosure Synchronous

Wrap a callback in a C closure while forwarding its arguments and results. This is useful when an API requires a C closure but your behavior is written in Luau.

Syntax
Luau
newcclosure(callback: Function, name: string?) -> Function

Parameters

Function parameters
ParameterTypeDescription
callbackFunctionThe function the wrapper will call.
namestring?Optional debug name for the wrapper.

Returns

Function

A new C closure. Its callback may yield when the surrounding call allows yielding.

Example

Example
Luau
local wrapped = newcclosure(function(a, b)
    return a + b
end, "add")
print(iscclosure(wrapped), wrapped(2, 3)) -- true, 5
Kawaii documentation