xref: /aosp_15_r20/external/lua/doc/readme.html (revision 088332b5b69e7ab13924864b272aabfc2509d2d5)
1*088332b5SXin Li<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2*088332b5SXin Li<HTML>
3*088332b5SXin Li<HEAD>
4*088332b5SXin Li<TITLE>Lua 5.4 readme</TITLE>
5*088332b5SXin Li<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
6*088332b5SXin Li<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
7*088332b5SXin Li<STYLE TYPE="text/css">
8*088332b5SXin Liblockquote, .display {
9*088332b5SXin Li	border: solid #a0a0a0 2px ;
10*088332b5SXin Li	border-radius: 8px ;
11*088332b5SXin Li	padding: 1em ;
12*088332b5SXin Li	margin: 0px ;
13*088332b5SXin Li}
14*088332b5SXin Li
15*088332b5SXin Li.display {
16*088332b5SXin Li	word-spacing: 0.25em ;
17*088332b5SXin Li}
18*088332b5SXin Li
19*088332b5SXin Lidl.display dd {
20*088332b5SXin Li	padding-bottom: 0.2em ;
21*088332b5SXin Li}
22*088332b5SXin Li
23*088332b5SXin Litt, kbd, code {
24*088332b5SXin Li	font-size: 12pt ;
25*088332b5SXin Li}
26*088332b5SXin Li</STYLE>
27*088332b5SXin Li</HEAD>
28*088332b5SXin Li
29*088332b5SXin Li<BODY>
30*088332b5SXin Li
31*088332b5SXin Li<H1>
32*088332b5SXin Li<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua"></A>
33*088332b5SXin LiWelcome to Lua 5.4
34*088332b5SXin Li</H1>
35*088332b5SXin Li
36*088332b5SXin Li<DIV CLASS="menubar">
37*088332b5SXin Li<A HREF="#about">about</A>
38*088332b5SXin Li&middot;
39*088332b5SXin Li<A HREF="#install">installation</A>
40*088332b5SXin Li&middot;
41*088332b5SXin Li<A HREF="#changes">changes</A>
42*088332b5SXin Li&middot;
43*088332b5SXin Li<A HREF="#license">license</A>
44*088332b5SXin Li&middot;
45*088332b5SXin Li<A HREF="contents.html">reference manual</A>
46*088332b5SXin Li</DIV>
47*088332b5SXin Li
48*088332b5SXin Li<H2><A NAME="about">About Lua</A></H2>
49*088332b5SXin Li<P>
50*088332b5SXin LiLua is a powerful, efficient, lightweight, embeddable scripting language
51*088332b5SXin Lideveloped by a
52*088332b5SXin Li<A HREF="http://www.lua.org/authors.html">team</A>
53*088332b5SXin Liat
54*088332b5SXin Li<A HREF="http://www.puc-rio.br/">PUC-Rio</A>,
55*088332b5SXin Lithe Pontifical Catholic University of Rio de Janeiro in Brazil.
56*088332b5SXin LiLua is
57*088332b5SXin Li<A HREF="#license">free software</A>
58*088332b5SXin Liused in
59*088332b5SXin Li<A HREF="http://www.lua.org/uses.html">many products and projects</A>
60*088332b5SXin Liaround the world.
61*088332b5SXin Li
62*088332b5SXin Li<P>
63*088332b5SXin LiLua's
64*088332b5SXin Li<A HREF="http://www.lua.org/">official web site</A>
65*088332b5SXin Liprovides complete information
66*088332b5SXin Liabout Lua,
67*088332b5SXin Liincluding
68*088332b5SXin Lian
69*088332b5SXin Li<A HREF="http://www.lua.org/about.html">executive summary</A>
70*088332b5SXin Liand
71*088332b5SXin Liupdated
72*088332b5SXin Li<A HREF="http://www.lua.org/docs.html">documentation</A>,
73*088332b5SXin Liespecially the
74*088332b5SXin Li<A HREF="http://www.lua.org/manual/5.4/">reference manual</A>,
75*088332b5SXin Liwhich may differ slightly from the
76*088332b5SXin Li<A HREF="contents.html">local copy</A>
77*088332b5SXin Lidistributed in this package.
78*088332b5SXin Li
79*088332b5SXin Li<H2><A NAME="install">Installing Lua</A></H2>
80*088332b5SXin Li<P>
81*088332b5SXin LiLua is distributed in
82*088332b5SXin Li<A HREF="http://www.lua.org/ftp/">source</A>
83*088332b5SXin Liform.
84*088332b5SXin LiYou need to build it before using it.
85*088332b5SXin LiBuilding Lua should be straightforward
86*088332b5SXin Libecause
87*088332b5SXin LiLua is implemented in pure ANSI C and compiles unmodified in all known
88*088332b5SXin Liplatforms that have an ANSI C compiler.
89*088332b5SXin LiLua also compiles unmodified as C++.
90*088332b5SXin LiThe instructions given below for building Lua are for Unix-like platforms,
91*088332b5SXin Lisuch as Linux and Mac OS X.
92*088332b5SXin LiSee also
93*088332b5SXin Li<A HREF="#other">instructions for other systems</A>
94*088332b5SXin Liand
95*088332b5SXin Li<A HREF="#customization">customization options</A>.
96*088332b5SXin Li
97*088332b5SXin Li<P>
98*088332b5SXin LiIf you don't have the time or the inclination to compile Lua yourself,
99*088332b5SXin Liget a binary from
100*088332b5SXin Li<A HREF="http://lua-users.org/wiki/LuaBinaries">LuaBinaries</A>.
101*088332b5SXin LiTry also
102*088332b5SXin Li<A HREF="http://luadist.org/">LuaDist</A>,
103*088332b5SXin Lia multi-platform distribution of Lua that includes batteries.
104*088332b5SXin Li
105*088332b5SXin Li<H3>Building Lua</H3>
106*088332b5SXin Li<P>
107*088332b5SXin LiIn most common Unix-like platforms, simply do "<KBD>make</KBD>".
108*088332b5SXin LiHere are the details.
109*088332b5SXin Li
110*088332b5SXin Li<OL>
111*088332b5SXin Li<LI>
112*088332b5SXin LiOpen a terminal window and move to
113*088332b5SXin Lithe top-level directory, which is named <TT>lua-5.4.1</TT>.
114*088332b5SXin LiThe <TT>Makefile</TT> there controls both the build process and the installation process.
115*088332b5SXin Li<P>
116*088332b5SXin Li<LI>
117*088332b5SXin Li  Do "<KBD>make</KBD>". The <TT>Makefile</TT> will guess your platform and build Lua for it.
118*088332b5SXin Li<P>
119*088332b5SXin Li<LI>
120*088332b5SXin Li  If the guess failed, do "<KBD>make help</KBD>" and see if your platform is listed.
121*088332b5SXin Li  The platforms currently supported are:
122*088332b5SXin Li<P>
123*088332b5SXin Li<P CLASS="display">
124*088332b5SXin Li   guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
125*088332b5SXin Li</P>
126*088332b5SXin Li<P>
127*088332b5SXin Li  If your platform is listed, just do "<KBD>make xxx</KBD>", where xxx
128*088332b5SXin Li  is your platform name.
129*088332b5SXin Li<P>
130*088332b5SXin Li  If your platform is not listed, try the closest one or posix, generic,
131*088332b5SXin Li  c89, in this order.
132*088332b5SXin Li<P>
133*088332b5SXin Li<LI>
134*088332b5SXin LiThe compilation takes only a few moments
135*088332b5SXin Liand produces three files in the <TT>src</TT> directory:
136*088332b5SXin Lilua (the interpreter),
137*088332b5SXin Liluac (the compiler),
138*088332b5SXin Liand liblua.a (the library).
139*088332b5SXin Li<P>
140*088332b5SXin Li<LI>
141*088332b5SXin Li  To check that Lua has been built correctly, do "<KBD>make test</KBD>"
142*088332b5SXin Li  after building Lua. This will run the interpreter and print its version.
143*088332b5SXin Li</OL>
144*088332b5SXin Li<P>
145*088332b5SXin LiIf you're running Linux, try "<KBD>make linux-readline</KBD>" to build the interactive Lua interpreter with handy line-editing and history capabilities.
146*088332b5SXin LiIf you get compilation errors,
147*088332b5SXin Limake sure you have installed the <TT>readline</TT> development package
148*088332b5SXin Li(which is probably named <TT>libreadline-dev</TT> or <TT>readline-devel</TT>).
149*088332b5SXin LiIf you get link errors after that,
150*088332b5SXin Lithen try "<KBD>make linux-readline MYLIBS=-ltermcap</KBD>".
151*088332b5SXin Li
152*088332b5SXin Li<H3>Installing Lua</H3>
153*088332b5SXin Li<P>
154*088332b5SXin Li  Once you have built Lua, you may want to install it in an official
155*088332b5SXin Li  place in your system. In this case, do "<KBD>make install</KBD>". The official
156*088332b5SXin Li  place and the way to install files are defined in the <TT>Makefile</TT>. You'll
157*088332b5SXin Li  probably need the right permissions to install files, and so may need to do "<KBD>sudo make install</KBD>".
158*088332b5SXin Li
159*088332b5SXin Li<P>
160*088332b5SXin Li  To build and install Lua in one step, do "<KBD>make all install</KBD>",
161*088332b5SXin Li  or "<KBD>make xxx install</KBD>",
162*088332b5SXin Li  where xxx is your platform name.
163*088332b5SXin Li
164*088332b5SXin Li<P>
165*088332b5SXin Li  To install Lua locally after building it, do "<KBD>make local</KBD>".
166*088332b5SXin Li  This will create a directory <TT>install</TT> with subdirectories
167*088332b5SXin Li  <TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>, <TT>share</TT>,
168*088332b5SXin Li  and install Lua as listed below.
169*088332b5SXin Li
170*088332b5SXin Li  To install Lua locally, but in some other directory, do
171*088332b5SXin Li  "<KBD>make install INSTALL_TOP=xxx</KBD>", where xxx is your chosen directory.
172*088332b5SXin Li  The installation starts in the <TT>src</TT> and <TT>doc</TT> directories,
173*088332b5SXin Li  so take care if <TT>INSTALL_TOP</TT> is not an absolute path.
174*088332b5SXin Li
175*088332b5SXin Li<DL CLASS="display">
176*088332b5SXin Li<DT>
177*088332b5SXin Li    bin:
178*088332b5SXin Li<DD>
179*088332b5SXin Li    lua luac
180*088332b5SXin Li<DT>
181*088332b5SXin Li    include:
182*088332b5SXin Li<DD>
183*088332b5SXin Li    lua.h luaconf.h lualib.h lauxlib.h lua.hpp
184*088332b5SXin Li<DT>
185*088332b5SXin Li    lib:
186*088332b5SXin Li<DD>
187*088332b5SXin Li    liblua.a
188*088332b5SXin Li<DT>
189*088332b5SXin Li    man/man1:
190*088332b5SXin Li<DD>
191*088332b5SXin Li    lua.1 luac.1
192*088332b5SXin Li</DL>
193*088332b5SXin Li
194*088332b5SXin Li<P>
195*088332b5SXin Li  These are the only directories you need for development.
196*088332b5SXin Li  If you only want to run Lua programs,
197*088332b5SXin Li  you only need the files in <TT>bin</TT> and <TT>man</TT>.
198*088332b5SXin Li  The files in <TT>include</TT> and <TT>lib</TT> are needed for
199*088332b5SXin Li  embedding Lua in C or C++ programs.
200*088332b5SXin Li
201*088332b5SXin Li<H3><A NAME="customization">Customization</A></H3>
202*088332b5SXin Li<P>
203*088332b5SXin Li  Three kinds of things can be customized by editing a file:
204*088332b5SXin Li<UL>
205*088332b5SXin Li    <LI> Where and how to install Lua &mdash; edit <TT>Makefile</TT>.
206*088332b5SXin Li    <LI> How to build Lua &mdash; edit <TT>src/Makefile</TT>.
207*088332b5SXin Li    <LI> Lua features &mdash; edit <TT>src/luaconf.h</TT>.
208*088332b5SXin Li</UL>
209*088332b5SXin Li
210*088332b5SXin Li<P>
211*088332b5SXin Li  You don't actually need to edit the Makefiles because you may set the
212*088332b5SXin Li  relevant variables in the command line when invoking make.
213*088332b5SXin Li  Nevertheless, it's probably best to edit and save the Makefiles to
214*088332b5SXin Li  record the changes you've made.
215*088332b5SXin Li
216*088332b5SXin Li<P>
217*088332b5SXin Li  On the other hand, if you need to customize some Lua features, you'll need
218*088332b5SXin Li  to edit <TT>src/luaconf.h</TT> before building and installing Lua.
219*088332b5SXin Li  The edited file will be the one installed, and
220*088332b5SXin Li  it will be used by any Lua clients that you build, to ensure consistency.
221*088332b5SXin Li  Further customization is available to experts by editing the Lua sources.
222*088332b5SXin Li
223*088332b5SXin Li<H3><A NAME="other">Building Lua on other systems</A></H3>
224*088332b5SXin Li<P>
225*088332b5SXin Li  If you're not using the usual Unix tools, then the instructions for
226*088332b5SXin Li  building Lua depend on the compiler you use. You'll need to create
227*088332b5SXin Li  projects (or whatever your compiler uses) for building the library,
228*088332b5SXin Li  the interpreter, and the compiler, as follows:
229*088332b5SXin Li
230*088332b5SXin Li<DL CLASS="display">
231*088332b5SXin Li<DT>
232*088332b5SXin Lilibrary:
233*088332b5SXin Li<DD>
234*088332b5SXin Lilapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c
235*088332b5SXin Lilauxlib.c lbaselib.c lcorolib.c ldblib.c liolib.c lmathlib.c loadlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c linit.c
236*088332b5SXin Li<DT>
237*088332b5SXin Liinterpreter:
238*088332b5SXin Li<DD>
239*088332b5SXin Li  library, lua.c
240*088332b5SXin Li<DT>
241*088332b5SXin Licompiler:
242*088332b5SXin Li<DD>
243*088332b5SXin Li  library, luac.c
244*088332b5SXin Li</DL>
245*088332b5SXin Li
246*088332b5SXin Li<P>
247*088332b5SXin Li  To use Lua as a library in your own programs, you'll need to know how to
248*088332b5SXin Li  create and use libraries with your compiler. Moreover, to dynamically load
249*088332b5SXin Li  C libraries for Lua, you'll need to know how to create dynamic libraries
250*088332b5SXin Li  and you'll need to make sure that the Lua API functions are accessible to
251*088332b5SXin Li  those dynamic libraries &mdash; but <EM>don't</EM> link the Lua library
252*088332b5SXin Li  into each dynamic library. For Unix, we recommend that the Lua library
253*088332b5SXin Li  be linked statically into the host program and its symbols exported for
254*088332b5SXin Li  dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter.
255*088332b5SXin Li  For Windows, we recommend that the Lua library be a DLL.
256*088332b5SXin Li  In all cases, the compiler luac should be linked statically.
257*088332b5SXin Li
258*088332b5SXin Li<P>
259*088332b5SXin Li  As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize
260*088332b5SXin Li  some features before building Lua.
261*088332b5SXin Li
262*088332b5SXin Li<H2><A NAME="changes">Changes since Lua 5.3</A></H2>
263*088332b5SXin Li<P>
264*088332b5SXin LiHere are the main changes introduced in Lua 5.4.
265*088332b5SXin LiThe
266*088332b5SXin Li<A HREF="contents.html">reference manual</A>
267*088332b5SXin Lilists the
268*088332b5SXin Li<A HREF="manual.html#8">incompatibilities</A> that had to be introduced.
269*088332b5SXin Li
270*088332b5SXin Li<H3>Main changes</H3>
271*088332b5SXin Li<UL>
272*088332b5SXin Li<LI> new generational mode for garbage collection
273*088332b5SXin Li<LI> to-be-closed variables
274*088332b5SXin Li<LI> const variables
275*088332b5SXin Li<LI> userdata can have multiple user values
276*088332b5SXin Li<LI> new implementation for math.random
277*088332b5SXin Li<LI> warning system
278*088332b5SXin Li<LI> debug information about function arguments and returns
279*088332b5SXin Li<LI> new semantics for the integer 'for' loop
280*088332b5SXin Li<LI> optional 'init' argument to 'string.gmatch'
281*088332b5SXin Li<LI> new functions 'lua_resetthread' and 'coroutine.close'
282*088332b5SXin Li<LI> string-to-number coercions moved to the string library
283*088332b5SXin Li<LI> allocation function allowed to fail when shrinking a memory block
284*088332b5SXin Li<LI> new format '%p' in 'string.format'
285*088332b5SXin Li<LI> utf8 library accepts codepoints up to 2^31
286*088332b5SXin Li</UL>
287*088332b5SXin Li
288*088332b5SXin Li<H2><A NAME="license">License</A></H2>
289*088332b5SXin Li<P>
290*088332b5SXin Li<A HREF="http://www.opensource.org/docs/definition.php">
291*088332b5SXin Li<IMG SRC="osi-certified-72x60.png" ALIGN="right" ALT="[osi certified]" STYLE="padding-left: 30px ;">
292*088332b5SXin Li</A>
293*088332b5SXin LiLua is free software distributed under the terms of the
294*088332b5SXin Li<A HREF="http://www.opensource.org/licenses/mit-license.html">MIT license</A>
295*088332b5SXin Lireproduced below;
296*088332b5SXin Liit may be used for any purpose, including commercial purposes,
297*088332b5SXin Liat absolutely no cost without having to ask us.
298*088332b5SXin Li
299*088332b5SXin LiThe only requirement is that if you do use Lua,
300*088332b5SXin Lithen you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.
301*088332b5SXin Li
302*088332b5SXin LiFor details, see
303*088332b5SXin Li<A HREF="http://www.lua.org/license.html">this</A>.
304*088332b5SXin Li
305*088332b5SXin Li<BLOCKQUOTE STYLE="padding-bottom: 0em">
306*088332b5SXin LiCopyright &copy; 1994&ndash;2020 Lua.org, PUC-Rio.
307*088332b5SXin Li
308*088332b5SXin Li<P>
309*088332b5SXin LiPermission is hereby granted, free of charge, to any person obtaining a copy
310*088332b5SXin Liof this software and associated documentation files (the "Software"), to deal
311*088332b5SXin Liin the Software without restriction, including without limitation the rights
312*088332b5SXin Lito use, copy, modify, merge, publish, distribute, sublicense, and/or sell
313*088332b5SXin Licopies of the Software, and to permit persons to whom the Software is
314*088332b5SXin Lifurnished to do so, subject to the following conditions:
315*088332b5SXin Li
316*088332b5SXin Li<P>
317*088332b5SXin LiThe above copyright notice and this permission notice shall be included in
318*088332b5SXin Liall copies or substantial portions of the Software.
319*088332b5SXin Li
320*088332b5SXin Li<P>
321*088332b5SXin LiTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
322*088332b5SXin LiIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
323*088332b5SXin LiFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
324*088332b5SXin LiAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
325*088332b5SXin LiLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
326*088332b5SXin LiOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
327*088332b5SXin LiTHE SOFTWARE.
328*088332b5SXin Li</BLOCKQUOTE>
329*088332b5SXin Li<P>
330*088332b5SXin Li
331*088332b5SXin Li<P CLASS="footer">
332*088332b5SXin LiLast update:
333*088332b5SXin LiWed Sep 30 09:55:45 UTC 2020
334*088332b5SXin Li</P>
335*088332b5SXin Li<!--
336*088332b5SXin LiLast change: revised for Lua 5.4.1
337*088332b5SXin Li-->
338*088332b5SXin Li
339*088332b5SXin Li</BODY>
340*088332b5SXin Li</HTML>
341