[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Process pipelines in Lua
- From: Reuben Thomas <rrt@...>
- Date: Sun, 17 Mar 2013 22:42:46 +0000
The latest (5.1.27) of luaposix has a somewhat experimental addition,
posix.pipeline, which allows process pipelines to be constructed in
Lua, a mixture of shell commands and forked Lua functions run in
subprocesses.
For example, you can write something like:
posix.pipeline({
"tail -3 COPYING",
"wc",
function () s = posix.read(posix.STDIN_FILENO, 1000) print (s) end
})
Even more experimentally, there's an iterator which adds an extra
process and pipes the output of the end of the pipeline back into the
calling process.
Normally, posix.pipe is used to construct the pipe, but any function
that returns paired file descriptors also works, e.g. posix.openpty.
The reason for mentioning all this on the list is that I think it's
pretty cool (being able to write process pipelines simply in Lua), but
I have no idea if it's of interest to anyone else, and, if so, whether
the API and, secondarily, code, seem sensible.
I'm already using it in another project for coloring the output of
command-line commands:
https://github.com/rrthomas/cw
Comments about the pipeline code and API are most welcome,
particularly on the relevant github issue
https://github.com/luaposix/luaposix/issues/74
--
http://rrt.sc3d.org