[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Assign and Deassign meta functions
- From: Chris Smith <space.dandy@...>
- Date: Fri, 12 Jul 2019 07:52:30 +0100
I mentioned this in another thread but the idea has been festering in my mind over the last few days. The idea is simply that an object’s metatable can have _assign and _deassign methods which are invoked when that object is (de)assigned to/from a variable, for example:
f = io.open(‘a’) — __assign called on result of io.open(‘a’)
local x = f — f.__assign() called
local y = x — x.__assign() called
y = ’something else’ — y.__deassign() followed by (’something else’).__assign()
end — implicit x.__deassign() and y.__deassign() because they are going out of scope.
It seems to me that this would be a much more general way to implement <toclose> and other similar mechanisms and I’d really like to know if it’s been considered before, and if so what the arguments for and against were.
Chris Smith <firstname.lastname@example.org>