Closures

newlclosure

Returns a Luau closure that calls the provided function.

Syntax

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

Arguments

NameTypeDescription
funcfunctionFunction called by the returned Luau closure.
debugName?stringOptional debug name for the generated closure.

Returns

NameTypeDescription
closurefunctionGenerated Luau closure that executes return the original function(..) and forwards arguments to the original function.

Description

Returns a Luau closure that calls the provided function. The first argument must be a function.

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 Luau closure that calls the original function.

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

local wrapped = newlclosure(add, "add")

print(wrapped(2, 3))
print(islclosure(wrapped))