lua-users home
lua-l archive

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


On Wed, Jul 7, 2010 at 04:52, Hisham <hisham.hm@gmail.com> wrote:
> On Tue, Jul 6, 2010 at 7:19 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
>> On Tue, Jul 6, 2010 at 21:10, Hisham <hisham.hm@gmail.com> wrote:

<...>

> I played around a bit here with piping, and given that io.popen can
> only do reading or writing but not both, we're limited in what we can
> do to emulate shell pipes -- I think we'll have to end up using
> constructs that actually build shell pipes (ie, os.execute("foo |
> bar")).

I vaguely recall that on Windows pipes and output redirection are in
rather sad state.

That being said, can't we code some cross-platform C module for
bidirectional piping? (Using obscure API calls on Windows if
necessary.) (Never done that on Windows, so can't say if it is
possible.)

> My quick experiments follow attached. The testpipe.lua example
> doesn't fully work, because I forgot that #pipe doesn't work because
> you can't override # for tables in Lua 5.1. The -pipe trick felt like
> a neat way to trigger evaluation after a chain of __call's, though.

That's a neat trick indeed. I never thought about using unary minus
for this... Something to keep in mind while designing DSLs.

> However, I think a number of the things we use pipes for in shell
> script (grep, wc, sort and the like) can be reimplemented as pure Lua
> functions in this library, or would simply turn into things like
> table.sort in Lua scripts.

> I believe that instead of focusing on duplicating sh features, it's
> more important to make it easy to manipulate data from external
> commands (a few utility functions to make iterators or tables out of
> the outputs could go a long way).

We still need piping, I think.

Because it seems to be a perfectly legible thing to do — to embed some
Lua code between shell commands.

>> Do you think that we need to support non-POSIX environments? (Since
>> you need this module for LuaRocks, I suppose that you do...)

<...>

> For this "shell programming module project", I think the "process
> execution module" could be written in pure Lua using os.execute and
> io.popen, and the "general utils module" could be written using
> LuaFileSystem for portability. Using lfs directly in scripts can be a
> bit too low-level at times (for example, luarocks.fs offers functions
> such as fs.copy, fs.move and fs.recursive_delete). LuaRocks also
> offers a pure-Lua module called luarocks.dir with things such
> dir.dir_name and dir.base_name, which also save a few forks.

Okay. It could be helpful to be able to use lua-posix, but lets keep
the module crossplatform.

Alexander.