xref: /redis-3.2.3/deps/lua/doc/lua.html (revision 21d3294c)
1*21d3294cSantirez<!-- $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ -->
2*21d3294cSantirez<HTML>
3*21d3294cSantirez<HEAD>
4*21d3294cSantirez<TITLE>LUA man page</TITLE>
5*21d3294cSantirez<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
6*21d3294cSantirez</HEAD>
7*21d3294cSantirez
8*21d3294cSantirez<BODY BGCOLOR="#FFFFFF">
9*21d3294cSantirez
10*21d3294cSantirez<H2>NAME</H2>
11*21d3294cSantirezlua - Lua interpreter
12*21d3294cSantirez<H2>SYNOPSIS</H2>
13*21d3294cSantirez<B>lua</B>
14*21d3294cSantirez[
15*21d3294cSantirez<I>options</I>
16*21d3294cSantirez]
17*21d3294cSantirez[
18*21d3294cSantirez<I>script</I>
19*21d3294cSantirez[
20*21d3294cSantirez<I>args</I>
21*21d3294cSantirez]
22*21d3294cSantirez]
23*21d3294cSantirez<H2>DESCRIPTION</H2>
24*21d3294cSantirez<B>lua</B>
25*21d3294cSantirezis the stand-alone Lua interpreter.
26*21d3294cSantirezIt loads and executes Lua programs,
27*21d3294cSantirezeither in textual source form or
28*21d3294cSantirezin precompiled binary form.
29*21d3294cSantirez(Precompiled binaries are output by
30*21d3294cSantirez<B>luac</B>,
31*21d3294cSantirezthe Lua compiler.)
32*21d3294cSantirez<B>lua</B>
33*21d3294cSantirezcan be used as a batch interpreter and also interactively.
34*21d3294cSantirez<P>
35*21d3294cSantirezThe given
36*21d3294cSantirez<I>options</I>
37*21d3294cSantirez(see below)
38*21d3294cSantirezare executed and then
39*21d3294cSantirezthe Lua program in file
40*21d3294cSantirez<I>script</I>
41*21d3294cSantirezis loaded and executed.
42*21d3294cSantirezThe given
43*21d3294cSantirez<I>args</I>
44*21d3294cSantirezare available to
45*21d3294cSantirez<I>script</I>
46*21d3294cSantirezas strings in a global table named
47*21d3294cSantirez<B>arg</B>.
48*21d3294cSantirezIf these arguments contain spaces or other characters special to the shell,
49*21d3294cSantirezthen they should be quoted
50*21d3294cSantirez(but note that the quotes will be removed by the shell).
51*21d3294cSantirezThe arguments in
52*21d3294cSantirez<B>arg</B>
53*21d3294cSantirezstart at 0,
54*21d3294cSantirezwhich contains the string
55*21d3294cSantirez'<I>script</I>'.
56*21d3294cSantirezThe index of the last argument is stored in
57*21d3294cSantirez<B>arg.n</B>.
58*21d3294cSantirezThe arguments given in the command line before
59*21d3294cSantirez<I>script</I>,
60*21d3294cSantirezincluding the name of the interpreter,
61*21d3294cSantirezare available in negative indices in
62*21d3294cSantirez<B>arg</B>.
63*21d3294cSantirez<P>
64*21d3294cSantirezAt the very start,
65*21d3294cSantirezbefore even handling the command line,
66*21d3294cSantirez<B>lua</B>
67*21d3294cSantirezexecutes the contents of the environment variable
68*21d3294cSantirez<B>LUA_INIT</B>,
69*21d3294cSantirezif it is defined.
70*21d3294cSantirezIf the value of
71*21d3294cSantirez<B>LUA_INIT</B>
72*21d3294cSantirezis of the form
73*21d3294cSantirez'@<I>filename</I>',
74*21d3294cSantirezthen
75*21d3294cSantirez<I>filename</I>
76*21d3294cSantirezis executed.
77*21d3294cSantirezOtherwise, the string is assumed to be a Lua statement and is executed.
78*21d3294cSantirez<P>
79*21d3294cSantirezOptions start with
80*21d3294cSantirez<B>'-'</B>
81*21d3294cSantirezand are described below.
82*21d3294cSantirezYou can use
83*21d3294cSantirez<B>'--'</B>
84*21d3294cSantirezto signal the end of options.
85*21d3294cSantirez<P>
86*21d3294cSantirezIf no arguments are given,
87*21d3294cSantirezthen
88*21d3294cSantirez<B>"-v -i"</B>
89*21d3294cSantirezis assumed when the standard input is a terminal;
90*21d3294cSantirezotherwise,
91*21d3294cSantirez<B>"-"</B>
92*21d3294cSantirezis assumed.
93*21d3294cSantirez<P>
94*21d3294cSantirezIn interactive mode,
95*21d3294cSantirez<B>lua</B>
96*21d3294cSantirezprompts the user,
97*21d3294cSantirezreads lines from the standard input,
98*21d3294cSantirezand executes them as they are read.
99*21d3294cSantirezIf a line does not contain a complete statement,
100*21d3294cSantirezthen a secondary prompt is displayed and
101*21d3294cSantirezlines are read until a complete statement is formed or
102*21d3294cSantireza syntax error is found.
103*21d3294cSantirezSo, one way to interrupt the reading of an incomplete statement is
104*21d3294cSantirezto force a syntax error:
105*21d3294cSantirezadding a
106*21d3294cSantirez<B>';'</B>
107*21d3294cSantirezin the middle of a statement is a sure way of forcing a syntax error
108*21d3294cSantirez(except inside multiline strings and comments; these must be closed explicitly).
109*21d3294cSantirezIf a line starts with
110*21d3294cSantirez<B>'='</B>,
111*21d3294cSantirezthen
112*21d3294cSantirez<B>lua</B>
113*21d3294cSantirezdisplays the values of all the expressions in the remainder of the
114*21d3294cSantirezline. The expressions must be separated by commas.
115*21d3294cSantirezThe primary prompt is the value of the global variable
116*21d3294cSantirez<B>_PROMPT</B>,
117*21d3294cSantirezif this value is a string;
118*21d3294cSantirezotherwise, the default prompt is used.
119*21d3294cSantirezSimilarly, the secondary prompt is the value of the global variable
120*21d3294cSantirez<B>_PROMPT2</B>.
121*21d3294cSantirezSo,
122*21d3294cSantirezto change the prompts,
123*21d3294cSantirezset the corresponding variable to a string of your choice.
124*21d3294cSantirezYou can do that after calling the interpreter
125*21d3294cSantirezor on the command line
126*21d3294cSantirez(but in this case you have to be careful with quotes
127*21d3294cSantirezif the prompt string contains a space; otherwise you may confuse the shell.)
128*21d3294cSantirezThe default prompts are "&gt; " and "&gt;&gt; ".
129*21d3294cSantirez<H2>OPTIONS</H2>
130*21d3294cSantirez<P>
131*21d3294cSantirez<B>-</B>
132*21d3294cSantirezload and execute the standard input as a file,
133*21d3294cSantirezthat is,
134*21d3294cSantireznot interactively,
135*21d3294cSantirezeven when the standard input is a terminal.
136*21d3294cSantirez<P>
137*21d3294cSantirez<B>-e </B><I>stat</I>
138*21d3294cSantirezexecute statement
139*21d3294cSantirez<I>stat</I>.
140*21d3294cSantirezYou need to quote
141*21d3294cSantirez<I>stat </I>
142*21d3294cSantirezif it contains spaces, quotes,
143*21d3294cSantirezor other characters special to the shell.
144*21d3294cSantirez<P>
145*21d3294cSantirez<B>-i</B>
146*21d3294cSantirezenter interactive mode after
147*21d3294cSantirez<I>script</I>
148*21d3294cSantirezis executed.
149*21d3294cSantirez<P>
150*21d3294cSantirez<B>-l </B><I>name</I>
151*21d3294cSantirezcall
152*21d3294cSantirez<B>require</B>('<I>name</I>')
153*21d3294cSantirezbefore executing
154*21d3294cSantirez<I>script</I>.
155*21d3294cSantirezTypically used to load libraries.
156*21d3294cSantirez<P>
157*21d3294cSantirez<B>-v</B>
158*21d3294cSantirezshow version information.
159*21d3294cSantirez<H2>SEE ALSO</H2>
160*21d3294cSantirez<B>luac</B>(1)
161*21d3294cSantirez<BR>
162*21d3294cSantirez<A HREF="http://www.lua.org/">http://www.lua.org/</A>
163*21d3294cSantirez<H2>DIAGNOSTICS</H2>
164*21d3294cSantirezError messages should be self explanatory.
165*21d3294cSantirez<H2>AUTHORS</H2>
166*21d3294cSantirezR. Ierusalimschy,
167*21d3294cSantirezL. H. de Figueiredo,
168*21d3294cSantirezand
169*21d3294cSantirezW. Celes
170*21d3294cSantirez<!-- EOF -->
171*21d3294cSantirez</BODY>
172*21d3294cSantirez</HTML>
173