[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: To-be-close confusion...
- From: David Heiko Kolf <david@...>
- Date: Sun, 16 Jun 2019 05:52:55 +0200
Sean Conner wrote:
> Given the following example code:
>
> local function readfile(name)
> local <toclose> f = io.open(name)
> if not f then return end
> local res = {}
> res.date = parse_date(f)
> if not res.date then return end
> res.name = parse_name(f)
> if not res.name then return end
> res.data = parse_data(f)
> if not res.data then return end
> return res
> end
I'd like to extend your example to include the error message from
io.open, in which case the current <toclose> syntax requires an extra
assignment:
local function readfile(name)
local openres, errmsg, errcode = io.open(name)
local <toclose> f = openres
if not f then return nil, errmsg, errcode end
-- the rest I left unchanged:
local res = {}
res.date = parse_date(f)
if not res.date then return end
res.name = parse_name(f)
if not res.name then return end
res.data = parse_data(f)
if not res.data then return end
return res
end
I think it is necessary to include full error handling in examples to
highlight the real use cases of the new syntax -- which I'd like to see
extended to "local <toclose> f, errmsg, errcode = io.open(name)".
Best regards,
David
(I hope I don't sound like a broken record yet.)