Reputation: 16724
Equivalent to main(int argc, char*argv[])
of C. For example: ./foo.lua -a -b
how do I read -a
and -b
from foo.lua
program?
Upvotes: 12
Views: 20018
Reputation: 2704
You can use the excellent argparse library. Docs are here: http://argparse.readthedocs.io/en/stable/
Upvotes: 1
Reputation: 72412
The command line arguments are also available as real arguments to the script, which are vararg functions. So you can do:
local x,y,z = ...
If you need to loop over the command line arguments, use the arg
table.
Upvotes: 7