[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [PATCH] Humble request: Invoke finalizers repeatedly for resurrected data
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 3 May 2014 17:54:24 -0300
> I know, I know, it is evil thing to do and I agree it is bad idea for
> regular code. But hear me out:
>
> local weak = setmetatable({}, {__mode="v"})
> local resmt = {A}
> function resmt.__gc(v)
> print("resurrecting")
> -- note that re-requesting finalizer is explicit like this
> weak.x = setmetatable(v, resmt)
> end
> weak.x = setmetatable({}, resmt)
> for i=1,10 do
> collectgarbage()
> end
> assert(weak.x)
I think Lua 5.3w2 already does that.
-- Roberto