Command-line arguments are a common way to parameterize execution of programs. For example, lua script.lua uses script.lua as an argument to the lua program.
To experiment with command-line arguments, save this script to a file (e.g., command_line_arguments.lua) and run it with Lua:
In Lua, command-line arguments are automatically available in the arg table. The program name is typically stored in arg[0], and the actual arguments start from arg[1]. Unlike Go, we don’t need to import any special packages to access command-line arguments.
Next, we’ll look at more advanced command-line processing techniques in Lua.