вт, 16 июл. 2019 г. в 00:13, Gé Weijers <ge@weijers.org>:
>
>
> You could make an array that calls __close on its contents whenever its own __close metamethod is called. This would not require recursion.
>
Show me code example.
Something like his (untested):
local function close_values(t)
for _, val in pairs(t) do
local <toclose> tmp = val
end
end
local <toclose> array = setmetatable({}, {__close = close_values})
When 'array' goes out of scope close_values will be called, which will call __close on all the values in the array.