[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Technical Note #6 & "chaining" a function to the GC cycle
- From: roberto@... (Roberto Ierusalimschy)
- Date: Tue, 17 Oct 2006 10:23:23 -0300
> The Lua Technical Note #6 says:
> "Instead of calling CheckDestructors() manually at some interval, the
> natural thing to do is chain it to Lua's garbage collection cycle. The
> Lua virtual machine supports this by calling the gc tag method for the
> nil type at the end of a cycle."
>
> I realise that this document was written for a much older version of
> Lua and a lot of it is probably out of date, but is there still any
> equivalent way to have Lua run a particular function after each
> garbage collection in the current version?
You can try something like this:
mt = {__gc = function ()
<do whatever you want here>
create_new_userdata_with_metatable(mt)
end
}
create_new_userdata_with_metatable(mt)
-- Roberto