types.WeakRef.constructor
weakrefReturns a weak reference to obj. This is what runs when types.WeakRef itself is called, types.WeakRef(obj) - the same conversion obj.weakref() performs as a method.
... from the prose below, not from the signature.Parameters
obj | any | the value to make a weak reference to |
Return value
A weakref pointing at obj, when obj is a reference-counted type (table, array, string, class, instance, function, generator, thread, weakref or userdata). For anything else - integer, float, bool, null - there is nothing to weakly reference, so obj itself comes back unchanged; see types.Integer.weakref for why.
Notes
Takes exactly one argument: types.WeakRef() and types.WeakRef(x, y) both throw a wrong-number-of-parameters error. The VM cannot show the real name obj here, since this binding carries a type mask instead of a declaration string and dumps the placeholder arg1 instead; that placeholder is what this page's params: front matter replaces. The receiver shown, (table|userdata|instance|class|null), is the same generic fallback explained on types.Integer.weakref - the binding has no receiver check, only the type check on obj.
Example
let types = require("types")
let t = {a = 1}
let wr = types.WeakRef(t)
println("type(wr) =", type(wr))
println("wr.ref() == t =", wr.ref() == t)
// a non-refcounted value has nothing to weakly reference
println("type(types.WeakRef(5)) =", type(types.WeakRef(5)))type(wr) = weakref
wr.ref() == t = true
type(types.WeakRef(5)) = integerSee also
ref | Returns the value this weakref points at, or null once that value is gone. |
weakref | Returns a weak reference to this weakref. |
weakref | Returns the integer itself. |
weakref | Returns a weak reference to the table. |
| weakref | class index |