lua-users home
lua-l archive

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


вт, 9 июл. 2019 г. в 01:23, Sergey Kovalev <kovserg33@gmail.com>:
>
> пн, 8 июл. 2019 г. в 20:33, Gé Weijers <ge@weijers.org>:
> >
> > Yes, you can do without "local <toclose>", but I would not call your example readable code. The point of adding features like this to a language is to make programs simpler and easier to understand by increasing the expressive power of the language.
> >
> > This is a whole lot more readable:
> >
> > local <toclose> f = assert(io.open("test.txt", "r"))

I think this is readable enough:
local f=auto(io.close){ io.open("test.txt","r") }
And it does do same things.

or even if you have to open group of files:
local files={}
for name in names do
  table.insert(files, auto(io.close){ io.open(name) } )
end