Functions & closuresReference
clonefunction
Represents copying of a function or closure.
Details#
Creates a separate callable copy of the supplied closure. Cloning is not a deep copy of captured tables or the environment: referenced values may remain shared. Use a clone to keep a callable value independently of the original function value.
Signature#
clonefunction(target: function): functionParameters#
| Parameter | Type | Description |
|---|---|---|
target | function | The exact function value to inspect or modify. |
Returns#
A callable clone; target must be a function.
Examples#
Example
local state = { value = 7 }
local function read() return state.value end
local copy = clonefunction(read)
print(copy()) -- 7
state.value = 9
print(copy()) -- 9