lua-users home
lua-l archive

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


On Mon, Jun 25, 2012 at 12:34 PM,  <meino.cramer@gmx.de> wrote:
> Hi,
>
> (Warning! Newbie ahead!)
>
> With UNIX systems you can build chains of cammands
> on the commandline eacht connected via stdout/stdin.
>
> Is it possible to chain lua-functions in a similiar way, that is:
> To create an output stream with one function which gets the
> input stream of another function?
>
> Is taht possible (portable...)?
>
> Thank you very much in advance for any help!
> Best regards,
> mcc
>

Why wouldn't it be?

function a(x)
    return x .. "a"
end

function b(x)
    return x .. "b"
end

print(b(a("t")) -- "tab"

Or if you like it better:

local l = { a, b }
local value = "t"
for _, fn in pairs(l) do
    value = fn(value)
end
print(value) -- "tab"

/s/ Adam