[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Error handling and Exception with an iterator.
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 6 Sep 2018 22:49:55 +0200
Op Do., 6 Sep. 2018 om 22:40 het Robert McLay <mclay@tacc.utexas.edu> geskryf:
>
> I have some code which does this under unix:
>
> local path = "/path/to/somewhere"
> local lfs = require("luafilesystem")
> local posix = require("posix")
> if (posix.access(path,"x")) then
> for f in lfs.dir(path) do
> ...
> end
> end
>
> The problem is that between the posix.access() test and the lfs.dir() call the permissions on path could change.
>
> What I would like instead is some way to ignore the error that lfs.dir() is causing. Normally one can ignore errors with pcall() but I don't see how to use pcall with an iterator like lfs.dir().
iterator = lfs.dir()
while true do
local f = pcall(iterator)
if not p then break end
...
end