|
|
||
|
Am 29.06.19 um 07:29 schröbte pocomane:
Of course you can simulate this with defer local obj = my_complex_object() defer getmetatable(obj).__close() end
Since function definitions allocate memory and thus can fail, this idiom isn't safe. You'd have to use the more awkward
local obj
defer
if obj then
getmetatable(obj).__close()
end
end
obj = my_complex_object()
And then you realize that Lua may allocate memory during function
*calls* (e.g. growing the stack). I don't think this is covered in the
current <toclose> approach either.
Philipp