Skip to main content
Turns function func into a C function.
The result classifies as a C closure - iscclosure, isnewcclosure, and isexecutorclosure all return true on it.
Already-newcclosure-wrapped functions are accepted too - each call adds another wrapper layer.
Most commonly used to disguise your Luau code as a built-in C function - so it passes iscclosure checks instead of failing them.

Parameters

Returns

function - a wrapper around func. When called, it runs the same body, but the wrapper itself reports as C.
Every call to newcclosure produces a new closure: newcclosure(f) ~= newcclosure(f).
The wrapper preserves identity context - both getthreadidentity and checkcaller inside the body see the same values they would outside.
If you save the wrapper as local wrapper = newcclosure(func) and then call wrapper("a", nil, "b"), the original func will still receive all three values in the same order - the nil in the middle stays put, instead of being skipped.

Example