lua-users home
lua-l archive

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


> In reply to myself ...maybe the subject is too cold by now... so sorry
> for insisting, but I've read all the long thread from February, and I
> still don't understand the idea behind the scope finalizers (in all
> their incarnations: the "with" syntax, the scoped locals, etc.). What
> I don't understand is how can scope exit know that an object should be
> finalized? What if it has any other references to it? For instance:
> 
> with f = file.open('somefile') do some_global = f end ... should f be
> closed by now? what would some_global hold now?
> 
> Could someone please get that off my head so I can sleep tonight? Thank you.

It is as if you insert a "f:close()" in the end of the scope. If there
are other references to the object, too bad. They will refer to a
finalized object.  Of course, you should not add a "close" at the end of
a scope if you are not sure the object won't be used any more. It is the
same with "with".  It basically saves you the hassle of adding a "close"
in all exit routes (including breaks, returns and errors).

-- Roberto