Quirrel4.41.0

types.Integer.weakref

Method on every integer
weakref(): any

Returns the integer itself.

Return value

this, unchanged - not a weakref value.

Notes

The signature above, (table|userdata|instance|class|null).weakref(), is not the real receiver: this binding carries no type check (it is registered identically on every built-in type), so the introspection tool falls back to a fixed placeholder list of five container-like types for display. integer is not even one of them, which shows that the list is a fallback and not a restriction; see types.String.constructor for the same placeholder on a different binding.

weakref() on an integer returns the integer because weakref() only does something for a reference-counted value: it calls sq_weakref, which checks whether the object is reference counted before creating an SQWeakRef, and an integer never is. float and bool behave the same way; see types.Float.weakref and types.Bool.weakref. A weakref of a weakref is different again, because a weakref object itself is reference counted - see types.WeakRef.weakref.

Example

examples/types/integer/weakref.nut
// Integers are not reference counted, so weakref() has nothing to point at:
// sq_weakref() just hands the value back unchanged.
let wr = (5).weakref()
println("wr =", wr)
println("type(wr) =", type(wr)) // still "integer", never "weakref"
Output:
wr = 5
type(wr) = integer

See also

weakrefReturns the float itself.
weakrefReturns the bool itself.
weakrefReturns a weak reference to this weakref.
refReturns the value this weakref points at, or null once that value is gone.
cloneReturns the integer itself.
integerclass index