[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A question wrt to-be-closed-variables
- From: v <v19930312@...>
- Date: Sun, 19 Sep 2021 15:39:25 +0300
On Sun, 2021-09-19 at 14:28 +0200, Marc Balmer wrote:
> Are may two assumptions below correct:
>
> - For many objects written in C, the __close and __gc metamethods can
> be the same?
Yes, but you need to take care to ensure that closed objects being
accessible won't cause issues (which is not the case for "traditional"
__gc metamethods). This includes attempting to close object twice in a
row, among other things.
> - If a <local> variable is closed (__close called), it will not be
> called by the garbagecollector?
No, as easily demonstrated:
do
local a <close> = setmetatable({}, {
__close = function() print('closed') end;
__gc = function() print('GCd') end;
})
end; --> closed
collectgarbage() --> GCd
--
v <v19930312@gmail.com>