NAME

lua - Lua interpreter

SYNOPSIS

lua [ arguments ]

DESCRIPTION

lua is the stand-alone Lua interpreter. It loads and executes Lua programs, either in textual source form or in precompiled binary form, as output by luac, the Lua compiler. lua can be used as a batch interpreter and also interactively.

The arguments can be options, assignments, or filenames, and are processed in order, from left to right.

Options start with - and are described below.

An assignment is an argument of the form a=b, which assigns the string .RB ` b ' to the global variable a. Note that no quotes are needed around the string if it does not contain spaces or other characters special to the shell. This is for convenience only. (In general, you should be careful when using quotes and spaces on the command line because they are usually handled by the shell.)

If the argument is neither an option nor an assignment, then it is assumed to be a filename, which is then loaded and executed.

If no arguments are given, then "-v -i" is assumed when the standard input is a terminal; otherwise, - is assumed.

OPTIONS

- load the standard input as a file, that is, not interactively, even when the standard input is a terminal.

-c close Lua before exiting.

-e "stat" execute statement stat. You will need to quote stat if it contains spaces or quotes.

-f "file" collect all remaining arguments as strings into a global table named arg and then execute file. The arguments in arg start at 0, which contains the string `file'. The index of the last argument is stored in "arg.n".

-i enter interactive mode, displaying a prompt. In this mode, lua reads lines from the standard input and executes them as they are read. Interactive mode is described below.

-q enter interactive mode, but without displaying a prompt.

-sn set the stack size to n. If present, this must be the first option. Note that n is in the same argument as -s. For example, to specify a stack size of 2000, use -s2000.

-v print version information.

INTERACTIVE MODE

The prompts shown are the value of the global variables _PROMPT, and _PROMPT2, if these values are strings. _PROMPT is displayed when lua is ready to read a command, and _PROMPT2 when it needs more input to complete a statement.

To change the prompt, set _PROMPT and _PROMPT2 to strings of your choice. You can do that after calling the interpreter or on the command line with _PROMPT='lua: ', for example. (Note the need for quotes, because the string contains a space.) The default prompts are ``> '' and ``>> ''.

lua allows the interactive use of ``=...'' as a shortcut for print(...). For example, =2+2,sqrt(4) prints 4    2.

lua may be compiled with support for the GNU readline(3) library, which provides command-line editing and history.

SEE ALSO

luac(1), readline(3)
http://www.tecgraf.puc-rio.br/lua/

DIAGNOSTICS

Error messages should be self explanatory.

AUTHORS

R. Ierusalimschy, L. H. de Figueiredo, and W. Celes (lua@tecgraf.puc-rio.br)