Returns a C closure that forwards every call to fn. The wrapper is indistinguishable from an engine C function to iscclosure, which is the point: it lets a Luau function pass anywhere a C function is expected.

Parameters

function
required
The function to wrap. See the note below on what happens when it is already a C closure.
string
An optional debug name for the wrapper.

Returns

function
A C closure that calls fn with the same arguments and returns its results.

Behavior

  • Already a C closure. If fn is already a C closure, it is returned unchanged, because there is nothing to wrap, so no new closure is created.
  • Wrapper reuse. If you wrap the same source function again and the previous wrapper is still reusable, Athena returns that existing wrapper rather than minting a new one. This keeps identity stable across repeated wrapping.
  • Environment carried over. The wrapper inherits the source function’s global environment, so getfenv/setfenv behavior is consistent between the two.
  • Yields. The wrapper forwards yields correctly, so wrapping a yielding function keeps it yielding.
A wrapper reports true from both iscclosure and isnewcclosure, and you can recover its original with getwrappedoriginal.

Example

Hand a Luau function to something that checks for a C closure:

Errors