lua-users home
lua-l archive

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


> On 3 Jul 2019, at 08:10, Sean Conner <sean@conman.org> wrote:
> 
> It was thus said that the Great Egor Skriptunoff once stated:
>> On Wed, Jul 3, 2019 at 9:19 AM Sean Conner <sean@conman.org> wrote:
>> 
>>>> Besides, it would be useful to have non-constant to-be-closed variables
>>> 
>>>  So, what exactly should happen in this code?
>>> 
>>>        local <toclose> f = io.open("a")
>>>        local x = f
>>>        f = io.open("b") -- should 'a' be closed?  or not because of x
>>>        f = io.open("c") -- should 'b' be closed?
>>> 
>>> 
>>> 
>> In your example only the last value in variable f would be evicted.
> 
>  Is that because of 'x'?  Or because that's the end of the scope?

It sounds like it might be better to have __assign and __deassign meta-functions, rather than <toclose>:

do
  f = io.open(‘a’) — __assign called on result of io.open(‘a’)
  local x = f — implicit f.__assign()
  local y = x — implicit x.__assign()

  y = ’something else’ — implicit y.__deassign() followed by (’something else’).__assign()
end — implicit x.__deassign() and y.__deassign() because they are going out of scope.

Regards,
Chris
—
Chris Smith <space.dandy@icloud.com>