lua-users home
lua-l archive

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


> However, allow me one final remark. It all depends on the reverse order 
> of calling the userdata __gc functions. If at any time in the future a 
> new implementation of the collection/clearing phase changes that, then 
> programs like this will break again. How certain can one be that this 
> will not happen? I therefore suggest that a change is made to unload 
> libraries in a last separate step, possibly in Lua 5.2.

Not only libraries, but many other things depend on this order. It is
not an implementation accident, but part of the language specification:

  http://www.lua.org/manual/5.1/manual.html#2.10.1
  At the end of each garbage-collection cycle, the finalizers for userdata
  are called in reverse order of their creation, among those collected in
  that cycle.

As we discussed in this list, probably this will actually change in 5.2,
but slightly: instead of the order of creation, what will count is the
order that a userdata got its metatable with a __gc field. Almost always
a userdata gets its metatable right after being created, so the change
will have a very small impact on programs (hopefully).

-- Roberto