lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

This is not an easy problem, especially when it comes to managing the
lifetime of a nested object.  What I've been doing is pushing the
nested udata on its parent creation and stuffing it in the parent's
env table.  When a method asking for the nested udata is called, I
grab it from there.

The catch with this method comes when the parent is collected but the
nested udata is still valid.  As I see it, there are 2 possible

1) Invalidate the boxed pointer the nested udata refers to (or some
equivalent marking of the memory as invalid) such that an error will
be thrown when used but will not cause a crash.

2) Have some kind of cyclic dependency such that the parent and child
will keep each other around as long as either one exists.