Imported from ../lua-5.0.2.tar.gz.
[lua.git] / doc / lua.html
blob073d4b525a578e9d3e44d641b596f0262c9b46b5
1 <!-- lua.man,v 1.8 2003/04/02 00:05:20 lhf Exp -->
2 <HTML>
3 <HEAD>
4 <TITLE>LUA man page</TITLE>
5 </HEAD>
7 <BODY BGCOLOR="#FFFFFF">
9 <H1>NAME</H1>
10 lua - Lua interpreter
11 <H1>SYNOPSIS</H1>
12 <B>lua</B>
14 <I>options</I>
17 <I>script</I>
19 <I>args</I>
22 <H1>DESCRIPTION</H1>
23 <B>lua</B>
24 is the stand-alone Lua interpreter.
25 It loads and executes Lua programs,
26 either in textual source form or
27 in precompiled binary form.
28 (Precompiled binaries are output by
29 <B>luac</B>,
30 the Lua compiler.)
31 <B>lua</B>
32 can be used as a batch interpreter and also interactively.
33 <P>
34 The given
35 <I>options</I>
36 (see below)
37 are executed and then
38 the Lua program in file
39 <I>script</I>
40 is loaded and executed.
41 The given
42 <I>args</I>
43 are available to
44 <I>script</I>
45 as strings in a global table named
46 <B>arg</B>.
47 If these arguments contain spaces or other characters special to the shell,
48 then they should be quoted
49 (but note that the quotes will be removed by the shell).
50 The arguments in
51 <B>arg</B>
52 start at 0,
53 which contains the string
54 `<I>script</I>'.
55 The index of the last argument is stored in
56 <B>"arg.n"</B>.
57 The arguments given in the command line before
58 <I>script</I>,
59 including the name of the interpreter,
60 are available in negative indices in
61 <B>arg</B>.
62 <P>
63 At the very start,
64 before even handling the command line,
65 <B>lua</B>
66 executes the contents of the environment variable
67 <B>LUA_INIT</B>,
68 if it is defined.
69 If the value of
70 <B>LUA_INIT</B>
71 is of the form
72 `@<I>filename</I>',
73 then
74 <I>filename</I>
75 is executed.
76 Otherwise, the string is assumed to be a Lua statement and is executed.
77 <P>
78 Options start with
79 <B>-</B>
80 and are described below.
81 You can use
82 <B>"--"</B>
83 to signal the end of options.
84 <P>
85 If no arguments are given,
86 then
87 <B>"-v -i"</B>
88 is assumed when the standard input is a terminal;
89 otherwise,
90 <B>"-"</B>
91 is assumed.
92 <P>
93 In interactive mode,
94 <B>lua</B>
95 prompts the user,
96 reads lines from the standard input,
97 and executes them as they are read.
98 If a line does not contain a complete statement,
99 then a secondary prompt is displayed and
100 lines are read until a complete statement is formed or
101 a syntax error is found.
102 So, one way to interrupt the reading of an incomplete statement is
103 to force a syntax error:
104 adding a
105 <B>`;' </B>
106 in the middle of a statement is a sure way of forcing a syntax error
107 (except inside multiline strings and comments; these must be closed explicitly).
108 If a line starts with
109 <B>`='</B>,
110 then
111 <B>lua</B>
112 displays the values of all the expressions in the remainder of the
113 line. The expressions must be separated by commas.
114 The primary prompt is the value of the global variable
115 <B>_PROMPT</B>,
116 if this value is a string;
117 otherwise, the default prompt is used.
118 Similarly, the secondary prompt is the value of the global variable
119 <B>_PROMPT2</B>.
121 to change the prompts,
122 set the corresponding variable to a string of your choice.
123 You can do that after calling the interpreter
124 or on the command line with
125 <B>"_PROMPT" "=\'lua: \'"</B>,
126 for example.
127 (Note the need for quotes, because the string contains a space.)
128 The default prompts are ``&gt; '' and ``&gt;&gt; ''.
129 <H1>OPTIONS</H1>
131 <B>-</B>
132 load and execute the standard input as a file,
133 that is,
134 not interactively,
135 even when the standard input is a terminal.
137 <B>-e "</B><I>stat"</I>
138 execute statement
139 <I>stat</I>.
140 You need to quote
141 <I>stat </I>
142 if it contains spaces, quotes,
143 or other characters special to the shell.
145 <B>-i</B>
146 enter interactive mode after
147 <I>script</I>
148 is executed.
150 <B>-l "</B><I>file"</I>
151 call
152 <B>require( file</B><I>)</I>
153 before executing
154 <I></I>script.
155 Typically used to load libraries
156 (hence the letter
157 <I>l</I>).
159 <B>-v</B>
160 show version information.
161 <H1>SEE ALSO</H1>
162 <B>luac</B>(1)
163 <BR>
164 <A HREF="http://www.lua.org/">http://www.lua.org/</A>
165 <H1>DIAGNOSTICS</H1>
166 Error messages should be self explanatory.
167 <H1>AUTHORS</H1>
168 R. Ierusalimschy,
169 L. H. de Figueiredo,
171 W. Celes
172 (<A HREF="mailto:lua-NO-SPAM-THANKS@tecgraf.puc-rio.br">lua AT tecgraf.puc-rio.br</A>)
173 <!-- EOF -->
174 </BODY>
175 </HTML>