lua-users home
lua-l archive

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


On Sun, Dec 12, 2010 at 05:28, Alexander Gladysh <agladysh@gmail.com> wrote:
> Hi, list!
>
> I want to pass command line arguments to a piece of code, that I
> specify with -e:
>
>    $ lua -e 'print(...)' 1 2 3
>
> What I see (as expected):
>
>    lua: cannot open 1: No such file or directory
>
> What I want to get:
>
>    1 2 3
>
> Is this possible?
>

Alexander,
here is a simple solution that works for me on Linux

Script file "lua-e" follows:

----%<----%<----
#!/usr/bin/env lua
-- evaluates 1st argument as lua string passing following arguments to the chunk
loadstring(arg[1])(select(2,...))
---->%---->%----

sh$ chmod u+x lua-e
sh$ ./lua-e 'print(...)' 1 2 3
1       2       3


Hope it helps,
--Leo--