lua-users home
lua-l archive

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


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