Files
CHOMPStation2/code/datums/weakref.dm
Leshana 66e9d9cfdf Unify datum var definitions
Inspired by https://github.com/tgstation/tgstation/pull/29636
Also consolidated some sideways overridden /datum/Delete() here to reduce proc-call overhead.
2017-12-29 14:23:13 -05:00

26 lines
559 B
Plaintext

//obtain a weak reference to a datum
/proc/weakref(datum/D)
if(!istype(D))
return
if(QDELETED(D))
return
if(!D.weakref)
D.weakref = new/weakref(D)
return D.weakref
/weakref
var/ref
/weakref/New(datum/D)
ref = "\ref[D]"
/weakref/Destroy()
// A weakref datum should not be manually destroyed as it is a shared resource,
// rather it should be automatically collected by the BYOND GC when all references are gone.
return QDEL_HINT_LETMELIVE
/weakref/proc/resolve()
var/datum/D = locate(ref)
if(D && D.weakref == src)
return D
return null