xref: /f-stack/app/redis-5.0.5/deps/lua/doc/lua.html (revision 572c4311)
1*572c4311Sfengbojiang<!-- $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ -->
2*572c4311Sfengbojiang<HTML>
3*572c4311Sfengbojiang<HEAD>
4*572c4311Sfengbojiang<TITLE>LUA man page</TITLE>
5*572c4311Sfengbojiang<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
6*572c4311Sfengbojiang</HEAD>
7*572c4311Sfengbojiang
8*572c4311Sfengbojiang<BODY BGCOLOR="#FFFFFF">
9*572c4311Sfengbojiang
10*572c4311Sfengbojiang<H2>NAME</H2>
11*572c4311Sfengbojianglua - Lua interpreter
12*572c4311Sfengbojiang<H2>SYNOPSIS</H2>
13*572c4311Sfengbojiang<B>lua</B>
14*572c4311Sfengbojiang[
15*572c4311Sfengbojiang<I>options</I>
16*572c4311Sfengbojiang]
17*572c4311Sfengbojiang[
18*572c4311Sfengbojiang<I>script</I>
19*572c4311Sfengbojiang[
20*572c4311Sfengbojiang<I>args</I>
21*572c4311Sfengbojiang]
22*572c4311Sfengbojiang]
23*572c4311Sfengbojiang<H2>DESCRIPTION</H2>
24*572c4311Sfengbojiang<B>lua</B>
25*572c4311Sfengbojiangis the stand-alone Lua interpreter.
26*572c4311SfengbojiangIt loads and executes Lua programs,
27*572c4311Sfengbojiangeither in textual source form or
28*572c4311Sfengbojiangin precompiled binary form.
29*572c4311Sfengbojiang(Precompiled binaries are output by
30*572c4311Sfengbojiang<B>luac</B>,
31*572c4311Sfengbojiangthe Lua compiler.)
32*572c4311Sfengbojiang<B>lua</B>
33*572c4311Sfengbojiangcan be used as a batch interpreter and also interactively.
34*572c4311Sfengbojiang<P>
35*572c4311SfengbojiangThe given
36*572c4311Sfengbojiang<I>options</I>
37*572c4311Sfengbojiang(see below)
38*572c4311Sfengbojiangare executed and then
39*572c4311Sfengbojiangthe Lua program in file
40*572c4311Sfengbojiang<I>script</I>
41*572c4311Sfengbojiangis loaded and executed.
42*572c4311SfengbojiangThe given
43*572c4311Sfengbojiang<I>args</I>
44*572c4311Sfengbojiangare available to
45*572c4311Sfengbojiang<I>script</I>
46*572c4311Sfengbojiangas strings in a global table named
47*572c4311Sfengbojiang<B>arg</B>.
48*572c4311SfengbojiangIf these arguments contain spaces or other characters special to the shell,
49*572c4311Sfengbojiangthen they should be quoted
50*572c4311Sfengbojiang(but note that the quotes will be removed by the shell).
51*572c4311SfengbojiangThe arguments in
52*572c4311Sfengbojiang<B>arg</B>
53*572c4311Sfengbojiangstart at 0,
54*572c4311Sfengbojiangwhich contains the string
55*572c4311Sfengbojiang'<I>script</I>'.
56*572c4311SfengbojiangThe index of the last argument is stored in
57*572c4311Sfengbojiang<B>arg.n</B>.
58*572c4311SfengbojiangThe arguments given in the command line before
59*572c4311Sfengbojiang<I>script</I>,
60*572c4311Sfengbojiangincluding the name of the interpreter,
61*572c4311Sfengbojiangare available in negative indices in
62*572c4311Sfengbojiang<B>arg</B>.
63*572c4311Sfengbojiang<P>
64*572c4311SfengbojiangAt the very start,
65*572c4311Sfengbojiangbefore even handling the command line,
66*572c4311Sfengbojiang<B>lua</B>
67*572c4311Sfengbojiangexecutes the contents of the environment variable
68*572c4311Sfengbojiang<B>LUA_INIT</B>,
69*572c4311Sfengbojiangif it is defined.
70*572c4311SfengbojiangIf the value of
71*572c4311Sfengbojiang<B>LUA_INIT</B>
72*572c4311Sfengbojiangis of the form
73*572c4311Sfengbojiang'@<I>filename</I>',
74*572c4311Sfengbojiangthen
75*572c4311Sfengbojiang<I>filename</I>
76*572c4311Sfengbojiangis executed.
77*572c4311SfengbojiangOtherwise, the string is assumed to be a Lua statement and is executed.
78*572c4311Sfengbojiang<P>
79*572c4311SfengbojiangOptions start with
80*572c4311Sfengbojiang<B>'-'</B>
81*572c4311Sfengbojiangand are described below.
82*572c4311SfengbojiangYou can use
83*572c4311Sfengbojiang<B>'--'</B>
84*572c4311Sfengbojiangto signal the end of options.
85*572c4311Sfengbojiang<P>
86*572c4311SfengbojiangIf no arguments are given,
87*572c4311Sfengbojiangthen
88*572c4311Sfengbojiang<B>"-v -i"</B>
89*572c4311Sfengbojiangis assumed when the standard input is a terminal;
90*572c4311Sfengbojiangotherwise,
91*572c4311Sfengbojiang<B>"-"</B>
92*572c4311Sfengbojiangis assumed.
93*572c4311Sfengbojiang<P>
94*572c4311SfengbojiangIn interactive mode,
95*572c4311Sfengbojiang<B>lua</B>
96*572c4311Sfengbojiangprompts the user,
97*572c4311Sfengbojiangreads lines from the standard input,
98*572c4311Sfengbojiangand executes them as they are read.
99*572c4311SfengbojiangIf a line does not contain a complete statement,
100*572c4311Sfengbojiangthen a secondary prompt is displayed and
101*572c4311Sfengbojianglines are read until a complete statement is formed or
102*572c4311Sfengbojianga syntax error is found.
103*572c4311SfengbojiangSo, one way to interrupt the reading of an incomplete statement is
104*572c4311Sfengbojiangto force a syntax error:
105*572c4311Sfengbojiangadding a
106*572c4311Sfengbojiang<B>';'</B>
107*572c4311Sfengbojiangin the middle of a statement is a sure way of forcing a syntax error
108*572c4311Sfengbojiang(except inside multiline strings and comments; these must be closed explicitly).
109*572c4311SfengbojiangIf a line starts with
110*572c4311Sfengbojiang<B>'='</B>,
111*572c4311Sfengbojiangthen
112*572c4311Sfengbojiang<B>lua</B>
113*572c4311Sfengbojiangdisplays the values of all the expressions in the remainder of the
114*572c4311Sfengbojiangline. The expressions must be separated by commas.
115*572c4311SfengbojiangThe primary prompt is the value of the global variable
116*572c4311Sfengbojiang<B>_PROMPT</B>,
117*572c4311Sfengbojiangif this value is a string;
118*572c4311Sfengbojiangotherwise, the default prompt is used.
119*572c4311SfengbojiangSimilarly, the secondary prompt is the value of the global variable
120*572c4311Sfengbojiang<B>_PROMPT2</B>.
121*572c4311SfengbojiangSo,
122*572c4311Sfengbojiangto change the prompts,
123*572c4311Sfengbojiangset the corresponding variable to a string of your choice.
124*572c4311SfengbojiangYou can do that after calling the interpreter
125*572c4311Sfengbojiangor on the command line
126*572c4311Sfengbojiang(but in this case you have to be careful with quotes
127*572c4311Sfengbojiangif the prompt string contains a space; otherwise you may confuse the shell.)
128*572c4311SfengbojiangThe default prompts are "&gt; " and "&gt;&gt; ".
129*572c4311Sfengbojiang<H2>OPTIONS</H2>
130*572c4311Sfengbojiang<P>
131*572c4311Sfengbojiang<B>-</B>
132*572c4311Sfengbojiangload and execute the standard input as a file,
133*572c4311Sfengbojiangthat is,
134*572c4311Sfengbojiangnot interactively,
135*572c4311Sfengbojiangeven when the standard input is a terminal.
136*572c4311Sfengbojiang<P>
137*572c4311Sfengbojiang<B>-e </B><I>stat</I>
138*572c4311Sfengbojiangexecute statement
139*572c4311Sfengbojiang<I>stat</I>.
140*572c4311SfengbojiangYou need to quote
141*572c4311Sfengbojiang<I>stat </I>
142*572c4311Sfengbojiangif it contains spaces, quotes,
143*572c4311Sfengbojiangor other characters special to the shell.
144*572c4311Sfengbojiang<P>
145*572c4311Sfengbojiang<B>-i</B>
146*572c4311Sfengbojiangenter interactive mode after
147*572c4311Sfengbojiang<I>script</I>
148*572c4311Sfengbojiangis executed.
149*572c4311Sfengbojiang<P>
150*572c4311Sfengbojiang<B>-l </B><I>name</I>
151*572c4311Sfengbojiangcall
152*572c4311Sfengbojiang<B>require</B>('<I>name</I>')
153*572c4311Sfengbojiangbefore executing
154*572c4311Sfengbojiang<I>script</I>.
155*572c4311SfengbojiangTypically used to load libraries.
156*572c4311Sfengbojiang<P>
157*572c4311Sfengbojiang<B>-v</B>
158*572c4311Sfengbojiangshow version information.
159*572c4311Sfengbojiang<H2>SEE ALSO</H2>
160*572c4311Sfengbojiang<B>luac</B>(1)
161*572c4311Sfengbojiang<BR>
162*572c4311Sfengbojiang<A HREF="http://www.lua.org/">http://www.lua.org/</A>
163*572c4311Sfengbojiang<H2>DIAGNOSTICS</H2>
164*572c4311SfengbojiangError messages should be self explanatory.
165*572c4311Sfengbojiang<H2>AUTHORS</H2>
166*572c4311SfengbojiangR. Ierusalimschy,
167*572c4311SfengbojiangL. H. de Figueiredo,
168*572c4311Sfengbojiangand
169*572c4311SfengbojiangW. Celes
170*572c4311Sfengbojiang<!-- EOF -->
171*572c4311Sfengbojiang</BODY>
172*572c4311Sfengbojiang</HTML>
173