lua-users home
lua-l archive

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


Francesco Abbate wrote:
>
> Please note that using an environment table for userdata does not
> work, I will explain why. Suppose that an object "a" depends on a
> second object "b". In order to ensure the finalisation order you set a
> reference to "b" in the env table of "a". This seems to work but
> suppose now that both "a" and "b" becomes unreachable. What happens is
> that Lua GC will free both of them regardless of the environment table
> of "a" and so the finalisation order can be violated.

As both, "a" and "b", become unreachable, Lua is right to collect both
of them.  And it will call the gc-method in reverse order of creation:
if "b" was created before "a" (should be, as "a" needs "b") it will
call "a.gc" and then "b.gc".

If Lua calls "a.gc" before "b.gc" even if "a" was created earlier than
"b" then it's a bug.

Ciao, ET.