newcclosure
Wraps a Luau function in a C function.
Syntax
newcclosure(func: function, debugname: string?) -> function
Also available as
new_c_closure
Parameters
| Parameter | Type | Description |
|---|---|---|
func | function | The Luau function to wrap. |
debugname | string? | Name reported by debug.info for the wrapper. Defaults to the wrapped function's own name. |
Returns
| Type | Description |
|---|---|
function | A C function that calls func with the same arguments and returns its results. |
Description
The wrapper behaves exactly like the function it wraps: it receives the same arguments, returns the same values, may yield, and passes errors through unchanged, including non-string error values such as tables. To inspection it is a C function: iscclosure returns true and it has no Luau constants or upvalues to read.
Use it when a compatibility API requires a C closure while the implementation is written in Luau. The wrapper preserves the callable behavior and changes its inspection category.
Example
local wrapped = newcclosure(function(a, b)
return a * b
end)
print(wrapped(6, 7))
print(iscclosure(wrapped))
print(iscustomcclosure(wrapped))
Notes
- Wrapping a function that is already a C function returns a new wrapper; it does not return the input.
- Errors keep their original value: a table thrown inside arrives as the same table.
These are Game executor contracts. Check build requirements and session lifetimes before using them.
