Quirrel4.41.0

types.Generator.tostring

Method on every generator
tostring(): any

Returns a string that names the type and identity of the generator.

Return value

A string shaped like (generator : 0x...), whatever state the generator is in. The address is the generator's own identity, not its progress: two generators created from the same function print two different addresses.

Notes

Takes no arguments; g.tostring(1) throws wrong number of parameters passed to native closure 'tostring' (2 passed, 1 required).

Because the address changes from run to run, code must never compare or print tostring() of a generator for anything other than a human to eyeball while debugging.

Example

examples/types/generator/tostring.nut
function geny() { yield 1 }
let g = geny()
let s = g.tostring()
println("s.slice(0, 12) =", s.slice(0, 12)) // "(generator :"
try { g.tostring(1) } catch(e) { println("g.tostring(1) throws:", e) }
Output:
s.slice(0, 12) = (generator :
g.tostring(1) throws: wrong number of parameters passed to native closure 'tostring' (2 passed, 1 required)

See also

getstatusReturns the generator's current state as a string.
tostringReturns a string that names the type and identity of the table.
generatorclass index