Syntax
clonefunction(func: function): functionArguments
| Name | Type | Description |
|---|---|---|
func | function | Function to clone. Passing a non-function raises a type error. |
Returns
| Name | Type | Description |
|---|---|---|
clone | function | New 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"))