Quirrel4.41.0

types.WeakRef.tostring

Method on every weakref
tostring(): any

Returns a string naming the type and identity of this weakref object itself - not of the value it points at.

Return value

A string shaped like (weakref : 0x...), the same generic format types.Table.tostring uses, since weakref has no _tostring metamethod of its own to override it.

Errors

The address in the result changes from run to run and between processes: never compare or print it verbatim in code whose output must stay stable, only match against the fixed part of the string, such as s.indexof("weakref") != null.

Notes

Takes no arguments. To see the pointed-to value's own string form instead, dereference first: wr.ref().tostring().

Example

examples/types/weakref/tostring.nut
let wr = {}.weakref()
let s = wr.tostring()
// format is "(weakref : 0x...)" - compare instead of printing the address
println("s.indexof(\"weakref\") != null =", s.indexof("weakref") != null)
println("type(s) =", type(s))
Output:
s.indexof("weakref") != null = true
type(s) = string

See also

refReturns the value this weakref points at, or null once that value is gone.
tostringReturns a string that names the type and identity of the table.
tostringConverts the integer to its decimal string form.
weakrefclass index