Quirrel4.41.0

types.Instance.is_frozen

Method on every instance
is_frozen(): any

Reports whether this reference to the instance was frozen with freeze().

Return value

true if the instance is immutable, false otherwise.

Notes

Takes no arguments. The immutable flag lives on the reference, not on the instance: freeze(someInstance) returns a new, frozen reference to the same instance, but a variable that already held it keeps pointing at an unfrozen reference. someInstance.is_frozen() stays false unless the variable itself is reassigned to the frozen result.

A frozen instance rejects rawset and swap with Cannot modify immutable object. clone() is not blocked by this flag: cloning a frozen instance gives back a plain, unfrozen instance, since the flag never survives a copy.

Example

examples/types/instance/is_frozen.nut
class Foo { x = 1 }
let inst = Foo()
println("inst.is_frozen() before freeze =", inst.is_frozen())
let frozenInst = freeze(inst)
println("frozenInst.is_frozen() =", frozenInst.is_frozen())
println("inst.is_frozen() after freeze =", inst.is_frozen())
Output:
inst.is_frozen() before freeze = false
frozenInst.is_frozen() = true
inst.is_frozen() after freeze = false

See also

rawsetReplaces the value stored at an existing field of this instance, without consulting a _newslot metamethod.
swapSwaps the values stored at two of this instance's fields.
freezeReturns a reference to obj with the immutable flag set.
instanceclass index