lua-users home
lua-l archive

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



I remember hearing newproxy mentioned a number of times on the list.

However, it still has not been added to the documentation, and a short glimpse on list archive shows Roberto calling it a "hack".

Has that status been changed since 2006, or is it going to?

-asko

http://lua-users.org/lists/lua-l/2006-06/msg00436.html


David Manura kirjoitti 23.1.2009 kello 6:53:

On Wed, Jan 21, 2009 at 4:20 AM, Asko Kauppi wrote:
Using traditional GC mechanism for these scopes is deterministic, since the whole Lua state is cleared at return/error. However, I could survey this a little further and maybe add some ease of use way to add "finalizers" to the
lanes.

In that case, either the caller or callee could have that
responsibility.  For example, the callee could probably do

 local function on_exit(f)
   local o = newproxy(true)
   getmetatable(o).__gc = f
   _G[{}] = o
 end

 on_exit(function() print 'deleting file..' end)

Yes, this seems like the way to go.

Thanks for the sample on using 'newproxy' - I haven't used it anywhere until now.


Similarly, in the more general case, one "could" call collectgarbage()
after every pcall to deterministically cleanup most objects, though
relying on this could be more error prone compared to an explicit
mechanism that disposes all objects out of scope, regardless if they
are finalizable.

With Lanes, the Lua state is actually closed after the pcall. That should be very deterministic. :)

-asko