├── logo.gif
├── README.md
├── osi-certified-72x60.png
├── manual.css
├── glossary.html
├── lua.css
├── lua.1
├── luac.1
├── index.html
└── contents.html
/logo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudwu/lua53doc/HEAD/logo.gif
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Lua 5.3 手册中文版
2 |
3 | https://cloudwu.github.io/lua53doc
4 |
--------------------------------------------------------------------------------
/osi-certified-72x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudwu/lua53doc/HEAD/osi-certified-72x60.png
--------------------------------------------------------------------------------
/manual.css:
--------------------------------------------------------------------------------
1 | h3 code {
2 | font-family: inherit ;
3 | font-size: inherit ;
4 | }
5 |
6 | pre, code {
7 | font-size: 12pt ;
8 | font-family: Consolas,"Liberation Mono",Menlo,Courier,monospace;
9 | }
10 |
11 | span.apii {
12 | float: right ;
13 | font-family: inherit ;
14 | font-style: normal ;
15 | font-size: small ;
16 | color: gray ;
17 | }
18 |
19 | p+h1, ul+h1 {
20 | font-style: normal ;
21 | padding-top: 0.4em ;
22 | padding-bottom: 0.4em ;
23 | padding-left: 16px ;
24 | margin-left: -16px ;
25 | background-color: #D0D0FF ;
26 | border-radius: 8px ;
27 | border: solid #000080 1px ;
28 | }
29 |
--------------------------------------------------------------------------------
/glossary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Lua 5.3 术语中英对照表
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | Lua 5.3 术语中英对照表
21 |
22 |
23 |
24 | 译者在翻译时,使用了一些尚未统一的中文术语译词,统一罗列如下:
25 |
26 |
27 | 元表 metatable
28 | 元方法 metamethod
29 | 弱表 weak table
30 | 协程 coroutine
31 | 闭包 closure
32 | 注册表 registry
33 | 让出 yield
34 | 表 table
35 | 用户数据 userdata
36 | 延续点 continuation
37 | 宿主 host
38 | 一等公民 first-class
39 | 语法糖 syntactic sugar
40 | 序列 sequence
41 | 异构 heterogeneous
42 | 终结器 finalizer
43 | 暂时表 ephemeron table
44 | 符记 token
45 | 字面串 literal string
46 | 代码块 chunk
47 | 标签 label
48 | 实例化 instantiated
49 | 上值 upvalue
50 |
51 |
52 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/lua.css:
--------------------------------------------------------------------------------
1 | html {
2 | background-color: #F8F8F8 ;
3 | }
4 |
5 | body {
6 | border: solid #a0a0a0 1px ;
7 | border-radius: 20px ;
8 | padding: 26px ;
9 | margin: 16px ;
10 | color: #000000 ;
11 | background-color: #FFFFFF ;
12 | font-family: "WenQuanYi Micro Hei", "Microsoft YaHei", Helvetica, Arial, sans-serif ;
13 | text-align: justify ;
14 | }
15 |
16 | h1, h2, h3, h4 {
17 | font-family: "WenQuanYi Micro Hei", "Microsoft YaHei", Helvetica, Verdana, Geneva, sans-serif ;
18 | font-weight: normal ;
19 | font-style: normal ;
20 | }
21 |
22 | h2 {
23 | padding-top: 0.4em ;
24 | padding-bottom: 0.4em ;
25 | padding-left: 0.8em ;
26 | padding-right: 0.8em ;
27 | background-color: #D0D0FF ;
28 | border-radius: 8px ;
29 | border: solid #a0a0a0 1px ;
30 | }
31 |
32 | h3 {
33 | padding-left: 0.5em ;
34 | border-left: solid #D0D0FF 1em ;
35 | }
36 |
37 | table h3 {
38 | padding-left: 0px ;
39 | border-left: none ;
40 | }
41 |
42 | a:link {
43 | color: #000080 ;
44 | background-color: inherit ;
45 | text-decoration: none ;
46 | }
47 |
48 | a:visited {
49 | background-color: inherit ;
50 | text-decoration: none ;
51 | }
52 |
53 | a:link:hover, a:visited:hover {
54 | color: #000080 ;
55 | background-color: #D0D0FF ;
56 | border-radius: 4px;
57 | }
58 |
59 | a:link:active, a:visited:active {
60 | color: #FF0000 ;
61 | }
62 |
63 | h1 a img {
64 | vertical-align: text-bottom ;
65 | }
66 |
67 | hr {
68 | border: 0 ;
69 | height: 1px ;
70 | color: #a0a0a0 ;
71 | background-color: #a0a0a0 ;
72 | display: none ;
73 | }
74 |
75 | table hr {
76 | display: block ;
77 | }
78 |
79 | :target {
80 | background-color: #F8F8F8 ;
81 | padding: 8px ;
82 | border: solid #a0a0a0 2px ;
83 | border-radius: 8px ;
84 | }
85 |
86 | .footer {
87 | color: gray ;
88 | font-size: x-small ;
89 | }
90 |
91 | input[type=text] {
92 | border: solid #a0a0a0 2px ;
93 | border-radius: 2em ;
94 | background-image: url('images/search.png') ;
95 | background-repeat: no-repeat ;
96 | background-position: 4px center ;
97 | padding-left: 20px ;
98 | height: 2em ;
99 | }
100 |
101 | pre.session {
102 | background-color: #F8F8F8 ;
103 | padding: 1em ;
104 | border-radius: 8px ;
105 | }
106 |
--------------------------------------------------------------------------------
/lua.1:
--------------------------------------------------------------------------------
1 | .TH LUA 1 "$Date: 2014/12/10 15:55:45 $"
2 | .SH NAME
3 | lua \- Lua interpreter
4 | .SH SYNOPSIS
5 | .B lua
6 | [
7 | .I options
8 | ]
9 | [
10 | .I script
11 | [
12 | .I args
13 | ]
14 | ]
15 | .SH DESCRIPTION
16 | .B lua
17 | is the standalone Lua interpreter.
18 | It loads and executes Lua programs,
19 | either in textual source form or
20 | in precompiled binary form.
21 | (Precompiled binaries are output by
22 | .BR luac ,
23 | the Lua compiler.)
24 | .B lua
25 | can be used as a batch interpreter and also interactively.
26 | .LP
27 | The given
28 | .I options
29 | are handled in order and then
30 | the Lua program in file
31 | .I script
32 | is loaded and executed.
33 | The given
34 | .I args
35 | are available to
36 | .I script
37 | as strings in a global table named
38 | .BR arg .
39 | If no options or arguments are given,
40 | then
41 | .B "\-v \-i"
42 | is assumed when the standard input is a terminal;
43 | otherwise,
44 | .B "\-"
45 | is assumed.
46 | .LP
47 | In interactive mode,
48 | .B lua
49 | prompts the user,
50 | reads lines from the standard input,
51 | and executes them as they are read.
52 | If the line contains an expression or list of expressions,
53 | then the line is evaluated and the results are printed.
54 | If a line does not contain a complete statement,
55 | then a secondary prompt is displayed and
56 | lines are read until a complete statement is formed or
57 | a syntax error is found.
58 | .LP
59 | At the very start,
60 | before even handling the command line,
61 | .B lua
62 | checks the contents of the environment variables
63 | .B LUA_INIT_5_3
64 | or
65 | .BR LUA_INIT ,
66 | in that order.
67 | If the contents is of the form
68 | .RI '@ filename ',
69 | then
70 | .I filename
71 | is executed.
72 | Otherwise, the string is assumed to be a Lua statement and is executed.
73 | .SH OPTIONS
74 | .TP
75 | .BI \-e " stat"
76 | execute statement
77 | .IR stat .
78 | .TP
79 | .B \-i
80 | enter interactive mode after executing
81 | .IR script .
82 | .TP
83 | .BI \-l " name"
84 | execute the equivalent of
85 | .IB name =require(' name ')
86 | before executing
87 | .IR script .
88 | .TP
89 | .B \-v
90 | show version information.
91 | .TP
92 | .B \-E
93 | ignore environment variables.
94 | .TP
95 | .B \-\-
96 | stop handling options.
97 | .TP
98 | .B \-
99 | stop handling options and execute the standard input as a file.
100 | .SH "SEE ALSO"
101 | .BR luac (1)
102 | .br
103 | The documentation at lua.org,
104 | especially section 7 of the reference manual.
105 | .SH DIAGNOSTICS
106 | Error messages should be self explanatory.
107 | .SH AUTHORS
108 | R. Ierusalimschy,
109 | L. H. de Figueiredo,
110 | W. Celes
111 | .\" EOF
112 |
--------------------------------------------------------------------------------
/luac.1:
--------------------------------------------------------------------------------
1 | .\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $
2 | .TH LUAC 1 "$Date: 2011/11/16 13:53:40 $"
3 | .SH NAME
4 | luac \- Lua compiler
5 | .SH SYNOPSIS
6 | .B luac
7 | [
8 | .I options
9 | ] [
10 | .I filenames
11 | ]
12 | .SH DESCRIPTION
13 | .B luac
14 | is the Lua compiler.
15 | It translates programs written in the Lua programming language
16 | into binary files containing precompiled chunks
17 | that can be later loaded and executed.
18 | .LP
19 | The main advantages of precompiling chunks are:
20 | faster loading,
21 | protecting source code from accidental user changes,
22 | and
23 | off-line syntax checking.
24 | Precompiling does not imply faster execution
25 | because in Lua chunks are always compiled into bytecodes before being executed.
26 | .B luac
27 | simply allows those bytecodes to be saved in a file for later execution.
28 | Precompiled chunks are not necessarily smaller than the corresponding source.
29 | The main goal in precompiling is faster loading.
30 | .LP
31 | In the command line,
32 | you can mix
33 | text files containing Lua source and
34 | binary files containing precompiled chunks.
35 | .B luac
36 | produces a single output file containing the combined bytecodes
37 | for all files given.
38 | Executing the combined file is equivalent to executing the given files.
39 | By default,
40 | the output file is named
41 | .BR luac.out ,
42 | but you can change this with the
43 | .B \-o
44 | option.
45 | .LP
46 | Precompiled chunks are
47 | .I not
48 | portable across different architectures.
49 | Moreover,
50 | the internal format of precompiled chunks
51 | is likely to change when a new version of Lua is released.
52 | Make sure you save the source files of all Lua programs that you precompile.
53 | .LP
54 | .SH OPTIONS
55 | .TP
56 | .B \-l
57 | produce a listing of the compiled bytecode for Lua's virtual machine.
58 | Listing bytecodes is useful to learn about Lua's virtual machine.
59 | If no files are given, then
60 | .B luac
61 | loads
62 | .B luac.out
63 | and lists its contents.
64 | Use
65 | .B \-l \-l
66 | for a full listing.
67 | .TP
68 | .BI \-o " file"
69 | output to
70 | .IR file ,
71 | instead of the default
72 | .BR luac.out .
73 | (You can use
74 | .B "'\-'"
75 | for standard output,
76 | but not on platforms that open standard output in text mode.)
77 | The output file may be one of the given files because
78 | all files are loaded before the output file is written.
79 | Be careful not to overwrite precious files.
80 | .TP
81 | .B \-p
82 | load files but do not generate any output file.
83 | Used mainly for syntax checking and for testing precompiled chunks:
84 | corrupted files will probably generate errors when loaded.
85 | If no files are given, then
86 | .B luac
87 | loads
88 | .B luac.out
89 | and tests its contents.
90 | No messages are displayed if the file loads without errors.
91 | .TP
92 | .B \-s
93 | strip debug information before writing the output file.
94 | This saves some space in very large chunks,
95 | but if errors occur when running a stripped chunk,
96 | then the error messages may not contain the full information they usually do.
97 | In particular,
98 | line numbers and names of local variables are lost.
99 | .TP
100 | .B \-v
101 | show version information.
102 | .TP
103 | .B \-\-
104 | stop handling options.
105 | .TP
106 | .B \-
107 | stop handling options and process standard input.
108 | .SH "SEE ALSO"
109 | .BR lua (1)
110 | .br
111 | The documentation at lua.org.
112 | .SH DIAGNOSTICS
113 | Error messages should be self explanatory.
114 | .SH AUTHORS
115 | R. Ierusalimschy,
116 | L. H. de Figueiredo,
117 | W. Celes
118 | .\" EOF
119 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Lua 5.3 readme
5 |
6 |
7 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | Lua 5.3 欢迎你
35 |
36 |
37 |
38 | 关于
39 | ·
40 | 安装
41 | ·
42 | 变更
43 | ·
44 | 许可证
45 | ·
46 | 参考手册
47 | ·
48 | 中英术语对照表
49 |
50 |
51 |
52 |
53 | Lua 是一门强大、快速、轻量的嵌入式脚本语言。它由巴西里约热内卢 Pontifical Catholic 大学的
54 | PUC-Rio
55 | 团队
56 | 开发。
57 | Lua 是一个
58 | 自由软件 ,
59 | 广泛应用于世界上无数产品和项目。
60 |
61 |
62 | Lua 的
63 | 官方网站
64 | 上提供了关于 Lua 的完整信息,
65 | 包括
66 | 综合概要
67 | 和最新的
68 | 文档 ,
69 | 需要注意的是
70 | 参考手册 可能和
71 | 这里的版本 有所不同。
72 |
73 |
74 |
75 |
76 | Lua 以
77 | 源代码
78 | 的形式发布,使用之前,你需要构建它。
79 | 构建 Lua 非常简单,因为 Lua 是用纯粹的 ANSI C 实现的,在所有具备 ANSI C 编译器的平台都可以直接编译。
80 | 同时,Lua 也可以直接以 C++ 形式编译。
81 | 下面介绍了类 Unix 平台上的构建流程,另有
82 | 其它系统构建介绍
83 | 与
84 | 配置选项 以作参考。
85 |
86 |
87 | 如果你没有时间或兴趣自己编译 Lua,
88 | 可以从
89 | LuaBinaries 获取编译后的二进制文件
90 | 或者从
91 | LuaDist 这里获取 Lua 的多平台发布版(自带电池)。
92 |
93 |
构建 Lua
94 |
95 |
96 | 在大多数类 Unix 平台上,输入 "make " 加上合适的平台名即可。步骤如下:
97 |
98 |
99 |
100 | 打开一个控制台窗口,切换到 lua-5.3.0 目录。
101 | 目录下的 Makefile 文件内包含了构建与安装流程。
102 |
103 |
104 | 运行 "make " 并查看你的平台是否列在其中。
105 | 当前支持的平台有:
106 |
107 |
108 | aix bsd c89 freebsd generic linux macosx mingw posix solaris
109 |
110 |
111 | 如果你的平台在其中,运行 "make xxx " 即可,xxx 代表你的平台名。
112 |
113 | 如果你的平台不在其中,先尝试最相近的平台,再按 posix generic c89 顺序依次尝试。
114 |
115 |
116 | 编译过程很短,最终在 src 目录下生成三个文件:
117 | lua (解释器),
118 | luac (编译器)和 liblua.a (静态库) 。
119 |
120 |
121 | 构建完成后,可以运行 "make test " 来检查是否成功。
122 | 它会运行解释器并打印版本号。
123 |
124 |
125 | 如果你是 Linux 系统并出现了编译错误,请确认你是否安装了
126 | readline (也可能叫 libreadline-dev 或者 readline-devel )开发包。
127 | 之后,如果还有链接错误,尝试
128 | "make linux MYLIBS=-ltermcap " 。
129 |
130 |
安装 Lua
131 |
132 | 一旦你构建完毕,可能希望把 Lua 安装到系统默认位置,
133 | 那么执行 "make install " 即可。
134 | 系统默认位置以及如何安装都定义在 Makefile 中。
135 | 这个过程可能需要有相关的权限。
136 |
137 |
138 | 运行 "make xxx install " 可以构建和安装一步到位,xxx 指你的平台名。
139 |
140 |
141 | 如果你想把 Lua 安装在本地,运行 "make local "。
142 | 它会创建一个 install 目录,内有
143 | bin , include , lib , man , share ,
144 | 子目录,并将下列文件安装在其中。
145 |
146 | 如果你想安装到本地其它目录,
147 | 运行 "make install INSTALL_TOP=xxx ",xxx 指你选择的目录。
148 | 由于安装过程中会切换到 src 以及 doc 目录进行,
149 | 所以当 INSTALL_TOP 不是绝对路径时务必小心。
150 |
151 |
152 |
153 | bin:
154 |
155 | lua luac
156 |
157 | include:
158 |
159 | lauxlib.h lua.h lua.hpp luaconf.h lualib.h
160 |
161 | lib:
162 |
163 | liblua.a
164 |
165 | man/man1:
166 |
167 | lua.1 luac.1
168 |
169 |
170 |
171 | 这些是开发时需要的目录。
172 | 如果你仅仅想运行一些 Lua 程序,
173 | 那么只需要 bin 和 man 下的文件。
174 | include 和 lib 下的文件用于将 Lua 嵌入
175 | C 或 C++ 程序。
176 |
177 |
178 |
179 | 有三类定制,可以通过编辑文件完成:
180 |
181 | 怎样安装 Lua 以及安装到哪里 — 编辑 Makefile 。
182 | 怎样构建 Lua — 编辑 src/Makefile 。
183 | Lua 特性 — 编辑 src/luaconf.h 。
184 |
185 |
186 |
187 | 其实你不必编辑 Makefile 文件,make 的时候在命令行指定相关变量即可。
188 | 当然,编辑保存 Makefile 可以给定制留个记录。
189 |
190 |
191 | 另一方面,如果你需要定制一些 Lua 特性,那就需要在构建安装 Lua 前
192 | 编辑 src/luaconf.h 。
193 | 编辑过的文件必须确保一致性,也就是只安装在一个地方,
194 | 让所有你编译出来的用到 Lua 的程序都使用这唯一的这一份。
195 | 专家可以通过编辑 Lua 源代码来定制更多的东西。
196 |
197 |
198 |
199 |
200 | 如果你不使用常规的 Unix 工具,那么构建 Lua 的流程就取决于你使用的编译器。
201 | 你需要创建若干工程来构建库,解释器以及编译器等。请把下列源文件加入相关工程:
202 |
203 |
204 |
205 | 库:
206 |
207 | lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
208 | lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c
209 | ltm.c lundump.c lvm.c lzio.c
210 | lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c
211 | lmathlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c linit.c
212 |
213 | 解释器:
214 |
215 | library, lua.c
216 |
217 | 编译器:
218 |
219 | library, luac.c
220 |
221 |
222 |
223 | 把 Lua 以一个库形式用于你的程序,你需要知道如何用你的编译器创建库和使用库。
224 | 比如,以动态加载的 C 库形式使用 Lua,你需要了解如何创建动态库并让 Lua API 函数
225 | 在动态库中可见 — 不要 将 Lua 库链入每个动态库。
226 | 在 Unix 下,我们建议把 Lua 库静态链入宿主程序,然后将符号导出用于动态链接;
227 | src/Makefile 就是这样处理 Lua 解释器的。
228 | 在 Windows 下,我们建议把 Lua 库编译成一个 DLL 。
229 | 无论怎样,编译器 luac 都应该静态链接。
230 |
231 |
232 | 正如上面所述,你可以在构建 Lua 前编辑 src/luaconf.h
233 | 以定制一些特性。
234 |
235 |
236 |
237 |
238 | 这里列出了 Lua 5.3 引入的主要变更。
239 | 参考手册
240 | 中列出了
241 | 不兼容的地方 。
242 |
243 |
主要变化
244 |
245 | 整数 (默认 64 位)
246 | 32 位整数的官方支持
247 | 位操作符
248 | 基本的 utf-8 支持
249 | 值的打包及解包函数
250 |
251 |
252 |
253 | 这些是 Lua 5.3 引入的其它变更:
254 | 语言
255 |
256 | 用户数据可以是任意 Lua 值
257 | 整数除法
258 | 某些元方法有了更加灵活的规则
259 |
260 |
261 | 库
262 |
263 | ipairs 以及表处理库都会考虑元方法
264 | string.dump 多了裁减选项
265 | 表处理库考虑了元方法
266 | 新函数 table.move
267 | 新函数 string.pack
268 | 新函数 string.unpack
269 | 新函数 string.packsize
270 |
271 |
272 | C API
273 |
274 | 简化了延续点 API
275 | lua_gettable 以及类似函数会返回结果的值类型
276 | lua_dump 增加了裁减选项
277 | 新函数: lua_geti
278 | 新函数: lua_seti
279 | 新函数: lua_isyieldable
280 | 新函数: lua_numbertointeger
281 | 新函数: lua_rotate
282 | 新函数: lua_stringtonumber
283 |
284 |
285 | Lua 独立解释器
286 |
287 | 可以做计算器使用;不再需要前置 '='
288 | arg 表对所有代码都可用
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 | Lua is free software distributed under the terms of the
298 | MIT license
299 | reproduced below;
300 | it may be used for any purpose, including commercial purposes,
301 | at absolutely no cost without having to ask us.
302 |
303 | The only requirement is that if you do use Lua,
304 | then you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.
305 |
306 | For details, see
307 | this .
308 |
309 |
310 | Copyright © 1994–2015 Lua.org, PUC-Rio.
311 |
312 |
313 | Permission is hereby granted, free of charge, to any person obtaining a copy
314 | of this software and associated documentation files (the "Software"), to deal
315 | in the Software without restriction, including without limitation the rights
316 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
317 | copies of the Software, and to permit persons to whom the Software is
318 | furnished to do so, subject to the following conditions:
319 |
320 |
321 | The above copyright notice and this permission notice shall be included in
322 | all copies or substantial portions of the Software.
323 |
324 |
325 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
326 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
327 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
328 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
329 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
330 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
331 | THE SOFTWARE.
332 |
333 |
334 |
335 |
336 |
340 |
341 |
342 |
343 |
--------------------------------------------------------------------------------
/contents.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Lua 5.3 参考手册 - 目录
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | Lua 5.3 参考手册
21 |
22 |
23 |
24 | 这份参考手册是对 Lua 语言的官方定义。
25 | 关于 Lua 编程的全部细节,则放在
26 | Programming in Lua
27 | 这本书中。
28 |
29 |
30 | 开始
31 | ·
32 | 目录
33 | ·
34 | 索引
35 | ·
36 | 中英术语对照表
37 |
38 |
39 | Lua.org, PUC-Rio 版权所有 © 2015 ,
40 | 在遵循
41 | Lua license
42 | 条款下,可自由使用。
43 |
44 |
45 |
46 |
141 |
142 |
143 |
612 |
613 |
614 |
618 |
619 |
620 |
621 |
--------------------------------------------------------------------------------