lua-shellio

Created: 2014-05-19 07:48
Updated: 2017-11-08 11:36
lua

README.mkd

lua-shellio

Using lua-filterpipe, this package provides convenience wrapper functions around the classic binutils and/or coreutils like cat, tac, head, tail etc so that they can be used with ease as filters from Lua programs.

In addition, this package provides a pipe object that makes using Unix pipelines in Lua programs extremely easy. It stores the pipeline's output and can be referred to or continued at any later point. Here's how it works:

local sh = require 'shellio'

-- let's get a list of a user's connection endpoints!

local P = sh.Pipe.new()
  ("lsof", "-i")
  ("grep", os.getenv("USER"))
  ("awk", "-F->", "{print $2}")
  ("cut", "-d:", "-f1")

print(P.data) -- the .data member contains the pipe's output

P("tac") -- continue processing the output

print(P.data) -- print the altered output

There's also a stack feature which keeps the results of every pipe component in memory. Just construct the pipe with a true argument:

local Q = sh.Pipe.new(true)

and after a pipe invocation,

Q.stack

will hold an array of all intermediate also the final result. You have to clear the stack memory manually. For this, just call the stack:

Q.stack()

If you call the stack with a non-nil argument,

Q.stack(true)

then this call is equivalent to

ipairs(Q.stack)

and may be used to construct an iterator over the stack elements.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more