views:

221

answers:

2

I wish to do

 lua prog.lua arg1 arg2

from the command line

Inside prog.lua, I want to say, for instance

print (arg1, arg2, '\n')

Lua doesn't seem to have argv[1] etc and the methods I've seen for dealing with command line arguments seem to be immature and / or cumbersome. Am I missing something?

+5  A: 

You're missing the arg vector, which has the elements you want in arg[1], arg[2], and so on:

% lua -i -- /dev/null one two three
Lua 5.1.3  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print(arg[2])
two
> 

More info in the Lua manual section on Lua standalone (thanks Miles!).

Norman Ramsey
You're absolutely right, I am! Whereabouts in the manual is that? I'm not finding my way round it very well ATM. Cheers
mr calendar
http://www.lua.org/manual/5.1/manual.html#6
Miles
+3  A: 

In addition to the arg table, ... contains the arguments (arg[1] and up) used to invoke the script.

% lua -i -- /dev/null one two three
Lua 5.1.3  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print(...)
one     two     three
daurnimator