lua-users home
lua-l archive

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


local contents
local f = io.open("myfile")
do
    contents = f:read()
finally
    f:close()
end

Imho this miss the point even more since the closing stuff is very distant from the initialization. What is the difference with just calling "close" at end of the scope?

The intent here is that the code in the `finally` section is called regardless of how the scope is exited: normal exit, exception, coroutine.close, etc.

It also supports doing things besides calling __close metamethods.

e