lua-users home
lua-l archive

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


> 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