lua-users home
lua-l archive

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


Peter Cawley wrote:
> A (non-nil) __gc field has to be present when the metatable is
> assigned in order for the UD to be placed on the appropriate GC list
> (the list of UDs with __gc). At collection time, the current value of
> __gc will be called, provided that the UD was on the appropriate list.
> Hence as long as there was a __gc, the new __gc will be called at
> collection.

A more subtle implication of this change is that the order of
userdata finalization now depends on the order in which the
userdatas have been assigned their metatables and not on the order
of their creation. This should be corrected in the manual. I doubt
this makes a difference in practice, though.

[The new GC I'm currently writing for LuaJIT will have exactly the
same restrictions on __gc being present when setting the metatable.
Let's see whether this breaks anything. I had to add a similar
restriction for __mode, but this is already covered by the manual
(though not enforced in Lua 5.1/5.2).]

About point 14: the experimental generational collector in Lua 5.2
is not enabled by default. And it's non-incremental, which means
it's less applicable to apps with a need for low-latency GC (games).

About point 42: the manual is wrong, io.lines(file, true) doesn't
work -- you need to use io.lines(file, "*L"). In fact you can do
this now:

  for odd,even in io.lines(file, "*l", "*l") do
    print("odd line:", odd)
    print("even line:", even)
  end

Or this:

  for a,b,c,tail in io.lines(file, 10, 5, 7, "*l") do
    -- split a file into fixed length columns
  end

--Mike