Lua Interpreter

The stand-alone interpreter,lua, is a console-based application that can be called with any sequence of the following arguments:

  • -sNUM
  • Sets stack size to NUM (must be the first option).
  • -
  • Executes stdin as a file.
  • -c
  • Calls lua_close after running all arguments.
  • -e \rmstat
  • Executes string stat.
  • -f filename
  • Executes filename with remaining args in table arg.
  • -i
  • Enters interactive mode with prompt.
  • -q
  • Enters interactive mode without prompt.
  • -v
  • Prints version information.
  • var=value
  • Sets global var to string "value"
  • filename
  • Executes file filename

Without arguments, the default is "lua -v -i" when stdin is a terminal, and "lua -" otherwise.All arguments are handled in order, except -c.

With "-f filename", all remaining arguments in the command line are passed to the Lua program in a table called arg; the field n gets the index of the last argument, and the field 0 gets "filename".

The getargs function can be used to access all command line arguments, with the called Lua executable file name in field 0. Field n is the index of the last argument.

A multi-line statement can be written by finishing intermediate lines with a backslash (‘\’). If the global variable _PROMPT is defined as a string, then its value is used as the prompt, allowing the prompt to be changed.

In Unix systems, Lua scripts can be made into executable programs by using:

chmod +x                    (sets the executable flag in Unix)
#!/usr/local/bin/lua        (path to Lua in the script header)
#!/usr/local/bin/lua -f …  (to get other arguments)