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 name for debugging/stack traces |
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 Debug Name
local function handler()
print("Handling request")
end
-- Wrap with a custom debug name
local wrapped = newcclosure(handler, "RequestHandler")
-- The debug name appears in stack traces and debug.infoNotes
- The wrapper has minimal performance overhead
- Errors are modified for hooking purposes
- The optional
debugnameparameter sets the function name for debugging
Related Functions
newlclosure- Wrap as Luau closureiscclosure- Check if C closureisnewcclosure- Check if newcclosure