Closures

newcclosure

Returns a C closure for the provided function.

Syntax

newcclosure(func: function, debugName?: string): function

Arguments

NameTypeDescription
funcfunctionFunction to return directly when it is already a C closure, or wrap in a wrapped C closure otherwise.
debugName?stringOptional debug name used for the created closure.

Returns

NameTypeDescription
closurefunctionThe original function when it is already a C closure, or a new C closure that calls the provided function.

Description

Returns a C closure for the provided function. If the function is already a C closure, the same function is returned. Passing a non-function raises a type error.

Call it with 2 parameter(s): func, debugName. The argument table explains which values are required and which ones only refine the behavior.

It returns closure (function). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Create a wrapped C closure for an L closure.

local function add(a, b)
    return a + b
end

local wrapped = newcclosure(add, "add")

print(wrapped(2, 3))
print(isnewcclosure(wrapped))