The Croc Programming Language
Weakrefs

Functions

word_t croc_weakref_push (CrocThread *t, word_t idx)
 
word_t croc_weakref_deref (CrocThread *t, word_t idx)
 

Detailed Description

Functions which operate on weakrefs.

Function Documentation

word_t croc_weakref_push ( CrocThread t,
word_t  idx 
)

Creates and pushes a weakref from the value at slot idx.

If the value is a value type or quasi-value type, the value will just be duplicated. Otherwise, a weakref object will be created (if one hasn't been created for that object already) and pushed. This mirrors the behavior of the Croc stdlib weakref function.

Returns
the stack index of the pushed value.
word_t croc_weakref_deref ( CrocThread t,
word_t  idx 
)

Given a weakref (or a value of any value or quasi-value type) at slot idx, pushes the referenced object.

If the value is a value or quasi-value type, just duplicates the value. Otherwise, it must be a weakref object, and the weakref's referent will be pushed (or null if it was collected). This mirrors the behavior of the Croc stdlib deref function.

Returns
the stack index of the pushed value.