lua-users home
lua-l archive

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


On Tue, 21 Jan 2020 at 05:38, Sean Conner <sean@conman.org> wrote:
>   Okay, let's see if the community can just come together to define the
> minimum viable module for directory functions.  I'm looking at three
> different modules that implement such functionality, LuaFileSystem, luaposix
> and my own org.conman.fsys module.
>
> [...]
>
>         okay = mkdir(name)
>         okay = rmdir(name)
>         okay = getcwd()
>         okay = setcwd(name)
>         cat = list([name])
>         cat = expand(glob)
>         fun,state,var = glist([name])
>         fun,state,var = gexpand(glob)
>         file = filename(name)
>         dir = dirname(name)
>
>   And that's it.  Additional information about files (like timestamps, size,
> type) is not in the scope for this module---this is just about directory
> manipulation.  Now imaging having to go through all this for other possible
> batteries, like additional file operations, network API, events, etc.

A couple obvious omissions (to me) are a way to test if a
file/directory exists (io.open might work on files, does it work
portably on directories?), and a way to tell if a filename is a
regular file, a directory (or something else). It could be a combined
fs.type that says nil (doesn't exist), "file", "directory", or
"other". I usually use lfs.attributes(path, 'mode') for these.

And on the other hand expand, gexpand, filename and dirname feel
redundant. I can see how they can be useful (I'd probably use them),
but that's basic string manipulation which Lua already excels at.