lua-users home
lua-l archive

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


On Sun, Dec 12, 2010 at 19:08, Leo Razoumov <slonik.az@gmail.com> wrote:
> On Sun, Dec 12, 2010 at 05: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

> 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

Clever trick! Thanks!

Alexander.