newcclosure
Wraps a Luau function to appear as a C closure.
Syntax
newcclosure(func: function, debugname?: string) -> functionParameters
| Parameter | Type | Description |
|---|---|---|
func | function | The Luau function to wrap |
debugname | string? | Optional debug name for the wrapper |
Returns
| Type | Description |
|---|---|
function | A C closure wrapper that calls the original function |
Description
newcclosure wraps a Luau function so that it appears to be a C closure when inspected. The wrapped function behaves identically but iscclosure will return true for it.
Example
local function myHook(...)
print("Hooked!")
return ...
end
-- Check before wrapping
print(iscclosure(myHook)) -- false
-- Wrap it
local wrapped = newcclosure(myHook)
-- Now it appears as a C closure
print(iscclosure(wrapped)) -- true
-- But still works the same
wrapped("test") -- Output: Hooked!With a Debug Name
local wrapped = newcclosure(function()
print("Handling request")
end, "RequestHandler")
wrapped()Notes
- The wrapper is yieldable
- It has no upvalues and reports errors with C-closure semantics
debugnamechanges the name shown by debug tooling
Related Functions
newlclosure- Wrap as Luau closureiscclosure- Check if C closureisnewcclosure- Check if newcclosure