newcclosure

Wraps a Luau function to appear as a C closure.

Syntax

newcclosure(func: function, debugname?: string) -> function

Parameters

ParameterTypeDescription
funcfunctionThe Luau function to wrap
debugnamestring?Optional debug name for the wrapper

Returns

TypeDescription
functionA 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
  • debugname changes the name shown by debug tooling