Closures

clonefunction

Creates and returns a separate function value for the function passed as the first argument.

Syntax

clonefunction(func: function): function

Arguments

NameTypeDescription
funcfunctionFunction to clone. Passing a non-function raises a type error.

Returns

NameTypeDescription
clonefunctionNew function produced by the newcclosure, C closure, or Luau closure clone path.

Description

Creates and returns a separate function value for the function passed as the first argument. The argument must be a function.

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

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

Example

Create a cloned closure from a function.

local function greet(name)
    return "Hello, " .. name
end

local cloned = clonefunction(greet)
print(cloned("Real"))