I have not found a way to create a destroy hook for objects that inherit from RootObj (or even futher down an inheritance hierarchy):
type Foo = ref object of RootObj
proc `=destroy`(foo: Foo) =
discard
Is there a way to accomplish this?
For more context, I have an object which holds a data structure from SDL that must be freed. When my object is destroyed, I need to call freeFoo on the object.
I do not know if this is the proper way of doing it but the following does work.
type
FooObj = object of RootObj
Foo = ref FooObj
proc `=destroy`(foo: var FooObj) =
echo "Destroy"
var foo = Foo()
Why would there be an implicit construction of the =destroy hook, perhaps because Image is a ptr object or Font is a pointer?
Even if that's the case, how would I gain control of the deconstruction so I can perform my own or additional operations?