lua-users home
lua-l archive

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


On Sun, Dec 12, 2010 at 13:46, Alex Bradbury <asb@asbradbury.org> wrote:
> On 12 December 2010 10:28, Alexander Gladysh <agladysh@gmail.com> wrote:
>> I want to pass command line arguments to a piece of code, that I
>> specify with -e:

>>    $ lua -e 'print(...)' 1 2 3

> How about this:

> echo "print(...)" | lua - 1 2 3

Unless I'm missing something, this will not allow the program to
access stdin. And I need it to be able to do this.

See this silly example:

$ cat > echo.lua
local echo = function(...)
  print("BEGIN", ...)
  for l in io.lines() do
    print("LINE", l, ...)
  end
  print("END", ...)
end

return
{
  echo = echo;
}
^D

$ echo 'require("echo").echo(...)' | lua - 1 2 3
BEGIN	1	2	3
END	1	2	3

Thanks,
Alexander.