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#
newcclosure(callback: function, name: string?): functionParameters#
| Parameter | Type | Description |
|---|---|---|
callback | function | Function to wrap; a C closure is returned unchanged. |
nameoptional | string | Optional debug label; default newcclosure. |
Returns#
A C-style callable for callback.
Examples#
Example
local wrapped = newcclosure(function(a, b) return a + b end, "add")
print(wrapped(2, 3)) -- 5
print(iscclosure(wrapped)) -- true