lua-users home
lua-l archive

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


On Tue, Nov 24, 2015 at 4:50 AM, Viacheslav Usov <via.usov@gmail.com> wrote:
> On Tue, Nov 24, 2015 at 3:10 AM, Patrick Donnelly <batrick@batbytes.com>
> wrote:
>
>> For Lua, we can simply annotate the local variable to indicate its value
>> should be cleaned up when the local scope ends.
>
> This is exactly what I proposed originally. But after a week of thinking my
> conclusion is that this is too weird, because it breaks a major assumption,
> See the details in my earlier message and the subsequent exchange with
> Roberto.

Sorry, one more message to respond to the "breaks a major assumption":
are you talking about the issue of calling __gc more than once on an
object? Or perhaps a block "hijacking" an object to close?

function a(foo)
  block bar = foo
  -- haha! I'm tricking Lua into calling getmetatable(foo).__gc(foo)
end

function b()
  local bar = io.open("file")
  a(bar)
end

I don't see this as a real issue because a could have simply called foo:close().

-- 
Patrick Donnelly