Quirrel4.41.0

types.Generator.clone

Method on every generator
clone(): any

Returns the generator itself: a generator has no separate clone identity.

Return value

The same generator clone was called on - clone g == g is always true, whatever state g is in.

Notes

clone is a keyword as well as a method name, so by default g.clone() and g.$clone() do not parse. Use the bracket form, g["clone"](), or the operator form, clone g. Both reach this same method. With #forbid-clone-operator the word is an ordinary identifier and g.$clone() compiles.

Example

examples/types/generator/clone.nut
function geny() { yield 1 }
let g = geny()
println("clone g == g =", clone g == g)
println("g[\"clone\"]() == g =", g["clone"]() == g)
Output:
clone g == g = true
g["clone"]() == g = true

See also

weakrefReturns a weak reference to the generator.
cloneReturns the closure itself: unlike a table, array or class instance, a closure has no separate clone identity.
generatorclass index