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?
Command line arguments are in the global table arg
. See here for details. Since there is no argparse/optparse library you will need to handle the logic for short and long switches yourself.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With