newcclosure
Do not implement this with coroutines
Many executors seem to be implementing this function using coroutine functions in Luau. Such functions will not pass sUNC checks.
The wrapped function must be yieldable, meaning that the function should be able to call task.wait, for example.
Error spoofing
Luau and C errors are different. You must ensure that errors from functions wrapped with newcclosure appear as C closure errors!
Upvalues
The function returned by newcclosure must have no upvalues.
newcclosure takes any Luau function and wraps it into a C closure.
When the returned function is called, it invokes the original Luau closure with the provided arguments, then passes the closure's returned values back to the caller.
Parameters
| Parameter | Description |
|---|---|
functionToWrap |
A function to be wrapped. |
Examples
Example 1
| Basic C closure wrapping example with newcclosure | |
|---|---|
Example 2
This example illustrates how Luau functions wrapped as a C closure should also be yieldable, therefore also showcasing how coroutine implementations of newcclosure would not work.