Skip to content
Functions & closuresReference

newcclosure

Represents creation of a native-style function wrapper.

Details#

Wraps a Luau callback in a C-style callable while preserving its arguments, results and environment. This does not compile Luau into machine code. A C closure is returned unchanged; repeated wrapping of the same callback may reuse a wrapper, so do not assume a fresh identity. The optional name is a debug label.

Signature#

Luau
newcclosure(callback: function, name: string?): function

Parameters#

ParameterTypeDescription
callbackfunctionFunction to wrap; a C closure is returned unchanged.
nameoptionalstringOptional debug label; default newcclosure.

Returns#

A C-style callable for callback.

Examples#

Example

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