|
Am 21.05.2014 23:44 schröbte Eric Wing:
I have another idea: What about splitting the A objects into two objects A and A_finalizer. The A_finalizer only lives in A's uservalue table, so it usually will become garbage at the same time as A. Whenever you associate a B object with the A object, you "disarm" the old A_finalizer, create a new one, and put both the B object and the new A_finalizer in A's uservalue table. Since the A_finalizer was created after the B object, it will be finalized before it.Nice thought.
I have tested this idea by now, and it works fine. You can even write a general `remark_for_finalization` function for all[*] userdata and put it in a library.
Philipp [*] my implementation still requires a uservalue table