Mercurial Hosting > luan
annotate website/src/manual.html.luan @ 485:c7acb40c6ca9
Added tag 0.8 for changeset 2e17b54e69d9
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 11 May 2015 21:23:02 -0600 |
parents | 7e9fcfbf22ec |
children | ddee9f5167d8 |
rev | line source |
---|---|
478 | 1 local Luan = require "luan:Luan" |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
2 local Io = require "luan:Io" |
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
3 local Html = require "luan:Html" |
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
4 local Http = require "luan:web/Http" |
387
23d075ce1e48
add website/src/Shared.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
386
diff
changeset
|
5 local Shared = require "site:/Shared" |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
6 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
7 heading_options = [[margin-top="1em"]] |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
8 |
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
9 function service() |
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
10 Io.stdout = Http.response.text_writer() |
391
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
11 %> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
12 <html> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
13 <head> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
14 <% Html.simply_html_head() %> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
15 <title>Luan Reference Manual</title> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
16 </head> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
17 <body> |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
18 |
372 | 19 <div container> |
387
23d075ce1e48
add website/src/Shared.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
386
diff
changeset
|
20 <% Shared.header() %> |
372 | 21 |
22 <h1>Luan Reference Manual</h1> | |
23 | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 <small> |
372 | 26 Original copyright © 2015 Lua.org, PUC-Rio. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 Freely available under the terms of the |
372 | 28 <a href="http://www.lua.org/license.html">Lua license</a>. |
29 Modified for Luan. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 </small> |
372 | 31 </p> |
32 | |
33 <hr/> | |
34 | |
35 <h2>Contents</h2> | |
36 | |
37 <div margin-bottom="1em"><a href="#intro">Introduction</a></div> | |
38 | |
373 | 39 <div margin-bottom="1em"> |
40 <a href="#basic">Basic Concepts</a> | |
41 <ul> | |
42 <li><a href="#types">Values and Types</a></li> | |
43 <li><a href="#env">Environments</a></li> | |
44 <li><a href="#error">Error Handling</a></li> | |
45 <li><a href="#meta">Metatables and Metamethods</a></li> | |
380 | 46 <li><a href="#gc">Garbage Collection</a></li> |
47 </ul> | |
48 </div> | |
49 | |
50 <div margin-bottom="1em"> | |
51 <a href="#lang">The Language</a> | |
52 <ul> | |
53 <li><a href="#lex">Lexical Conventions</a></li> | |
54 <li><a href="#vars">Variables</a></li> | |
389 | 55 <li> |
56 <a href="#stmts">Statements</a> | |
57 <ul> | |
58 <li><a href="#blocks">Blocks</a></li> | |
395 | 59 <li><a href="#chunks">Chunks</a></li> |
60 <li><a href="#assignment">Assignment</a></li> | |
61 <li><a href="#control">Control Structures</a></li> | |
62 <li><a href="#for">For Statement</a></li> | |
63 <li><a href="#fn_stmt">Function Calls as Statements</a></li> | |
64 <li><a href="#local_stmt">Local Declarations</a></li> | |
465 | 65 <li><a href="#template_stmt">Template Statements</a></li> |
395 | 66 </ul> |
67 </li> | |
68 <li> | |
69 <a href="#expressions">Expressions</a> | |
70 <ul> | |
71 <li><a href="#arithmetic">Arithmetic Operators</a></li> | |
396 | 72 <li><a href="#conversions">Coercions and Conversions</a></li> |
73 <li><a href="#relational">Relational Operators</a></li> | |
74 <li><a href="#logical_ops">Logical Operators</a></li> | |
75 <li><a href="#concatenation">Concatenation</a></li> | |
76 <li><a href="#length">The Length Operator</a></li> | |
77 <li><a href="#precedence">Precedence</a></li> | |
78 <li><a href="#constructors">Table Constructors</a></li> | |
417 | 79 <li><a href="#fn_calls">Function Calls</a></li> |
80 <li><a href="#fn_def">Function Definitions</a></li> | |
465 | 81 <li><a href="#template_expr">Template Expressions</a></li> |
389 | 82 </ul> |
83 </li> | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
84 <li><a href="#visibility">Visibility Rules</a></li> |
373 | 85 </ul> |
86 </div> | |
87 | |
468 | 88 <div margin-bottom="1em"> |
89 <a href="#libs">Standard Libraries</a> | |
90 <ul> | |
91 <li><a href="#default_lib">Default Environment</a></li> | |
470 | 92 <li><a href="#luan_lib">Basic Functions</a></li> |
476 | 93 <li><a href="#package_lib">Modules</a></li> |
468 | 94 </ul> |
95 </div> | |
96 | |
372 | 97 <hr/> |
98 | |
373 | 99 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
100 <h2 <%=heading_options%> ><a name="intro">Introduction</a></h2> |
372 | 101 |
102 <p>Luan is a high level programming language based on <a href="http://www.lua.org">Lua</a>. A great strength of Lua is its simplicity and Luan takes this even further, being even simpler than Lua. The goal is to provide a simple programming language for the casual programmer with as few concepts as possible so that one can quickly learn the language and then easily understand any code written in Luan.</p> | |
103 | |
104 <p>Luan is implemented in Java and is tightly coupled with Java. So it makes a great scripting language for Java programmers.</p> | |
105 | |
106 <p>Unlike Lua which is meant to be embedded, Luan is meant to be a full scripting language. This done not by adding feature to Luan, but rather by providing a complete set of libraries.</p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
107 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
108 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
109 <h2 <%=heading_options%> ><a name="basic">Basic Concepts</a></h2> |
373 | 110 |
111 <p>This section describes the basic concepts of the language.</p> | |
112 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
113 <h3 <%=heading_options%> ><a name="types">Values and Types</a></h3> |
373 | 114 |
115 <p> | |
116 Luan is a <i>dynamically typed language</i>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
117 This means that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
118 variables do not have types; only values do. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
119 There are no type definitions in the language. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
120 All values carry their own type. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
121 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
122 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
123 <p> |
373 | 124 All values in Luan are <i>first-class values</i>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
125 This means that all values can be stored in variables, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
126 passed as arguments to other functions, and returned as results. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
127 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
128 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
129 <p> |
373 | 130 There are eight basic types in Luan: |
131 <i>nil</i>, <i>boolean</i>, <i>number</i>, | |
132 <i>string</i>, <i>binary</i>, <i>function</i>, <i>userdata</i>, | |
133 and <i>table</i>. | |
134 <i>Nil</i> is the type of the value <b>nil</b>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
135 whose main property is to be different from any other value; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
136 it usually represents the absence of a useful value. |
373 | 137 <i>Nil</i> is implemented as the Java value <i>null</i>. |
138 <i>Boolean</i> is the type of the values <b>false</b> and <b>true</b>. | |
139 <i>Boolean</i> is implemented as the Java class <i>Boolean</i>. | |
140 <i>Number</i> represents both | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
141 integer numbers and real (floating-point) numbers. |
373 | 142 <i>Number</i> is implemented as the Java class <i>Number</i>. Any Java subclass of <i>Number</i> is allowed and this is invisible to the Luan user. Operations on numbers follow the same rules of |
143 the underlying Java implementation. | |
144 | |
145 <i>String</i> is implemented as the Java class <i>String</i>. | |
146 <i>Binary</i> is implemented as the Java type <i>byte[]</i>. | |
147 | |
148 | |
149 <p> | |
150 Luan can call (and manipulate) functions written in Luan and | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
151 functions written in Java (see <a href="#fn_calls">Function Calls</a>). |
373 | 152 Both are represented by the type <i>function</i>. |
153 | |
154 | |
155 <p> | |
156 The type <i>userdata</i> is provided to allow arbitrary Java objects to | |
157 be stored in Luan variables. | |
158 A userdata value is a Java object that isn't one of the standard Luan types. | |
159 Userdata has no predefined operations in Luan, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
160 except assignment and identity test. |
373 | 161 Userdata is useful then Java access is enabled in Luan |
162 | |
163 | |
164 | |
165 <p> | |
166 The type <i>table</i> implements associative arrays, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
167 that is, arrays that can be indexed not only with numbers, |
373 | 168 but with any Luan value except <b>nil</b>. |
169 Tables can be <i>heterogeneous</i>; | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
170 that is, they can contain values of all types (except <b>nil</b>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
171 Any key with value <b>nil</b> is not considered part of the table. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
172 Conversely, any key that is not part of a table has |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
173 an associated value <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
175 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
176 <p> |
373 | 177 Tables are the sole data-structuring mechanism in Luan; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
178 they can be used to represent ordinary arrays, sequences, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
179 symbol tables, sets, records, graphs, trees, etc. |
373 | 180 To represent records, Luan uses the field name as an index. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
181 The language supports this representation by |
373 | 182 providing <tt>a.name</tt> as syntactic sugar for <tt>a["name"]</tt>. |
183 There are several convenient ways to create tables in Luan | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
184 (see <a href="#constructors">Table Constructors</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
185 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
186 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
187 <p> |
373 | 188 We use the term <i>sequence</i> to denote a table where |
189 the set of all positive numeric keys is equal to {1..<i>n</i>} | |
190 for some non-negative integer <i>n</i>, | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
191 which is called the length of the sequence (see <a href="#length">The Length Operator</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
192 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
193 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
194 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
195 Like indices, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
196 the values of table fields can be of any type. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
197 In particular, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
198 because functions are first-class values, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
199 table fields can contain functions. |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
200 Thus tables can also carry <i>methods</i> (see <a href="#fn_def">Function Definitions</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
201 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
202 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
203 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
204 The indexing of tables follows |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
205 the definition of raw equality in the language. |
373 | 206 The expressions <tt>a[i]</tt> and <tt>a[j]</tt> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
207 denote the same table element |
373 | 208 if and only if <tt>i</tt> and <tt>j</tt> are raw equal |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
209 (that is, equal without metamethods). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
210 In particular, floats with integral values |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
211 are equal to their respective integers |
373 | 212 (e.g., <tt>1.0 == 1</tt>). |
213 | |
214 | |
215 <p> | |
216 Luan values are <i>objects</i>: | |
217 variables do not actually <i>contain</i> values, | |
218 only <i>references</i> to them. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
219 Assignment, parameter passing, and function returns |
373 | 220 always manipulate references to values; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
221 these operations do not imply any kind of copy. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
222 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
223 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
224 <p> |
478 | 225 The library function <a href="#Luan.type"><tt>Luan.type</tt></a> returns a string describing the type |
226 of a given value. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
227 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
228 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
229 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
230 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
231 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
232 <h3 <%=heading_options%> ><a name="env">Environments</a></h3> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
233 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
234 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
235 As will be discussed in <a href="#vars">Variables</a> and <a href=#assignment">Assignment</a>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
236 any reference to a free name |
373 | 237 (that is, a name not bound to any declaration) <tt>var</tt> |
238 is syntactically translated to <tt>_ENV.var</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
239 Moreover, every chunk is compiled in the scope of |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
240 an external local variable named <tt>_ENV</tt> (see <a href="#chunks">Chunks</a>), |
373 | 241 so <tt>_ENV</tt> itself is never a free name in a chunk. |
242 | |
243 | |
244 <p> | |
245 Despite the existence of this external <tt>_ENV</tt> variable and | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
246 the translation of free names, |
373 | 247 <tt>_ENV</tt> is a completely regular name. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 In particular, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
249 you can define new variables and parameters with that name. |
373 | 250 Each reference to a free name uses the <tt>_ENV</tt> that is |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
251 visible at that point in the program, |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
252 following the usual visibility rules of Luan (see <a href="#visibility">Visibility Rules</a>). |
373 | 253 |
254 | |
255 <p> | |
256 Any table used as the value of <tt>_ENV</tt> is called an <i>environment</i>. | |
257 | |
258 | |
259 <p> | |
260 When Luan loads a chunk, | |
261 the default value for its <tt>_ENV</tt> is an empty table. | |
262 | |
263 <p> | |
264 Luan also provides all chunks with two other local values: <tt>require</tt> and <tt>java</tt>. These are functions used to load and access libraries and other modules. | |
265 | |
266 | |
267 | |
268 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
269 <h3 <%=heading_options%> ><a name="error">Error Handling</a></h3> |
373 | 270 |
271 <p> | |
272 Luan code can explicitly generate an error by calling the | |
478 | 273 <a href="#Luan.error"><tt>error</tt></a> function. |
373 | 274 If you need to catch errors in Luan, |
478 | 275 you can use <a href="#Luan.pcall"><tt>pcall</tt></a> or <a href="#Luan.try"><tt>try</tt></a> |
373 | 276 to call a given function in <i>protected mode</i>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
277 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
278 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
279 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
280 Whenever there is an error, |
482 | 281 an <i>error table</i> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
282 is propagated with information about the error. |
482 | 283 See <a href="#Luan.new_error"><tt>Luan.new_error</tt></a>. |
373 | 284 |
285 | |
286 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
287 <h3 <%=heading_options%> ><a name="meta">Metatables and Metamethods</a></h3> |
373 | 288 |
289 <p> | |
290 Every table in Luan can have a <i>metatable</i>. | |
291 This <i>metatable</i> is an ordinary Luan table | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
292 that defines the behavior of the original value |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
293 under certain special operations. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
294 You can change several aspects of the behavior |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
295 of operations over a value by setting specific fields in its metatable. |
373 | 296 For instance, when a table is the operand of an addition, |
297 Luan checks for a function in the field "<tt>__add</tt>" of the table's metatable. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
298 If it finds one, |
373 | 299 Luan calls this function to perform the addition. |
300 | |
301 | |
302 <p> | |
303 The keys in a metatable are derived from the <i>event</i> names; | |
304 the corresponding values are called <ii>metamethods</i>. | |
305 In the previous example, the event is <tt>"add"</tt> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
306 and the metamethod is the function that performs the addition. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
307 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
308 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
309 <p> |
373 | 310 You can query the metatable of any table |
478 | 311 using the <a href="#Luan.get_metatable"><tt>get_metatable</tt></a> function. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
312 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
313 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
314 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
315 You can replace the metatable of tables |
478 | 316 using the <a href="#Luan.set_metatable"><tt>set_metatable</tt></a> function. |
373 | 317 |
318 | |
319 <p> | |
320 A metatable controls how a table behaves in | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
321 arithmetic operations, bitwise operations, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
322 order comparisons, concatenation, length operation, calls, and indexing. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
323 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
324 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
325 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
326 A detailed list of events controlled by metatables is given next. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
327 Each operation is identified by its corresponding event name. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
328 The key for each event is a string with its name prefixed by |
373 | 329 two underscores, '<tt>__</tt>'; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
330 for instance, the key for operation "add" is the |
373 | 331 string "<tt>__add</tt>". |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
332 Note that queries for metamethods are always raw; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
333 the access to a metamethod does not invoke other metamethods. |
373 | 334 You can emulate how Luan queries a metamethod for an object <tt>obj</tt> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
335 with the following code: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
336 |
382 | 337 <p><tt><pre> |
373 | 338 raw_get(get_metatable(obj) or {}, "__" .. event_name) |
382 | 339 </pre></tt></p> |
373 | 340 |
341 <p> | |
342 Here are the events: | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
343 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
344 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
345 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
346 <li><b>"add": </b> |
373 | 347 the <tt>+</tt> operation. |
348 | |
349 If any operand for an addition is a table, | |
350 Luan will try to call a metamethod. | |
351 First, Luan will check the first operand (even if it is valid). | |
352 If that operand does not define a metamethod for the "<tt>__add</tt>" event, | |
353 then Luan will check the second operand. | |
354 If Luan can find a metamethod, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
355 it calls the metamethod with the two operands as arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
356 and the result of the call |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
357 (adjusted to one value) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
358 is the result of the operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
359 Otherwise, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
360 it raises an error. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
361 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
362 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
363 <li><b>"sub": </b> |
373 | 364 the <tt>-</tt> operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
365 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
366 Behavior similar to the "add" operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
367 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
368 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
369 <li><b>"mul": </b> |
373 | 370 the <tt>*</tt> operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
371 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
372 Behavior similar to the "add" operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
373 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
374 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
375 <li><b>"div": </b> |
373 | 376 the <tt>/</tt> operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
377 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
378 Behavior similar to the "add" operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
379 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
380 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
381 <li><b>"mod": </b> |
373 | 382 the <tt>%</tt> operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
383 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
384 Behavior similar to the "add" operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
385 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
386 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
387 <li><b>"pow": </b> |
373 | 388 the <tt>^</tt> (exponentiation) operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
389 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
390 Behavior similar to the "add" operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
391 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
392 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
393 <li><b>"unm": </b> |
373 | 394 the <tt>-</tt> (unary minus) operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
395 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
396 Behavior similar to the "add" operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
397 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
398 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
399 <li><b>"concat": </b> |
373 | 400 the <tt>..</tt> (concatenation) operation. |
401 | |
402 Behavior similar to the "add" operation. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
403 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
404 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
405 <li><b>"len": </b> |
373 | 406 the <tt>#</tt> (length) operation. |
407 | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
408 If there is a metamethod, |
373 | 409 Luan calls it with the object as argument, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
410 and the result of the call |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
411 (always adjusted to one value) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
412 is the result of the operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
413 If there is no metamethod but the object is a table, |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
414 then Luan uses the table length operation (see <a href="#length">The Length Operator</a>). |
373 | 415 Otherwise, Luan raises an error. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
416 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
417 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
418 <li><b>"eq": </b> |
373 | 419 the <tt>==</tt> (equal) operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
420 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
421 Behavior similar to the "add" operation, |
373 | 422 except that Luan will try a metamethod only when the values |
423 being compared are both tables | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
424 and they are not primitively equal. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
425 The result of the call is always converted to a boolean. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
426 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
427 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
428 <li><b>"lt": </b> |
373 | 429 the <tt><</tt> (less than) operation. |
430 | |
431 Behavior similar to the "add" operation. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
432 The result of the call is always converted to a boolean. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
433 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
434 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
435 <li><b>"le": </b> |
373 | 436 the <tt><=</tt> (less equal) operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
437 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
438 Unlike other operations, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
439 The less-equal operation can use two different events. |
373 | 440 First, Luan looks for the "<tt>__le</tt>" metamethod in both operands, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
441 like in the "lt" operation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
442 If it cannot find such a metamethod, |
373 | 443 then it will try the "<tt>__lt</tt>" event, |
444 assuming that <tt>a <= b</tt> is equivalent to <tt>not (b < a)</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
445 As with the other comparison operators, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
446 the result is always a boolean. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
447 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
448 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
449 <li><b>"index": </b> |
373 | 450 The indexing access <tt>table[key]</tt>. |
451 | |
452 This event happens | |
453 when <tt>key</tt> is not present in <tt>table</tt>. | |
454 The metamethod is looked up in <tt>table</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
455 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
456 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
457 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
458 Despite the name, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
459 the metamethod for this event can be either a function or a table. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
460 If it is a function, |
373 | 461 it is called with <tt>table</tt> and <tt>key</tt> as arguments. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
462 If it is a table, |
373 | 463 the final result is the result of indexing this table with <tt>key</tt>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
464 (This indexing is regular, not raw, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
465 and therefore can trigger another metamethod.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
466 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
467 |
428
df95199ca4c0
rename __newindex to __new_index
Franklin Schmidt <fschmidt@gmail.com>
parents:
418
diff
changeset
|
468 <li><b>"new_index": </b> |
373 | 469 The indexing assignment <tt>table[key] = value</tt>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
470 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
471 Like the index event, |
373 | 472 this event happens when |
473 when <tt>key</tt> is not present in <tt>table</tt>. | |
474 The metamethod is looked up in <tt>table</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
475 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
476 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
477 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
478 Like with indexing, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
479 the metamethod for this event can be either a function or a table. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
480 If it is a function, |
373 | 481 it is called with <tt>table</tt>, <tt>key</tt>, and <tt>value</tt> as arguments. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
482 If it is a table, |
373 | 483 Luan does an indexing assignment to this table with the same key and value. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
484 (This assignment is regular, not raw, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
485 and therefore can trigger another metamethod.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
486 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
487 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
488 <p> |
428
df95199ca4c0
rename __newindex to __new_index
Franklin Schmidt <fschmidt@gmail.com>
parents:
418
diff
changeset
|
489 Whenever there is a "new_index" metamethod, |
373 | 490 Luan does not perform the primitive assignment. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
491 (If necessary, |
478 | 492 the metamethod itself can call <a href="#Luan.raw_set"><tt>raw_set</tt></a> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
493 to do the assignment.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
494 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
495 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
496 <li><b>"call": </b> |
373 | 497 The call operation <tt>func(args)</tt>. |
498 | |
499 This event happens when Luan tries to call a table. | |
500 The metamethod is looked up in <tt>func</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
501 If present, |
373 | 502 the metamethod is called with <tt>func</tt> as its first argument, |
503 followed by the arguments of the original call (<tt>args</tt>). | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
504 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
505 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
506 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
507 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
508 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
509 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
510 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
511 <h3 <%=heading_options%> ><a name="gc">Garbage Collection</a></h3> |
380 | 512 |
513 <p> | |
514 Luan uses Java's garbage collection. | |
515 | |
516 | |
517 | |
518 | |
519 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
520 <h2 <%=heading_options%> ><a name="lang">The Language</a></h2> |
380 | 521 |
522 <p> | |
523 This section describes the lexis, the syntax, and the semantics of Luan. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
524 In other words, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
525 this section describes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
526 which tokens are valid, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
527 how they can be combined, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
528 and what their combinations mean. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
529 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
530 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
531 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
532 Language constructs will be explained using the usual extended BNF notation, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
533 in which |
380 | 534 {<i>a</i>} means 0 or more <i>a</i>'s, and |
535 [<i>a</i>] means an optional <i>a</i>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
536 Non-terminals are shown like non-terminal, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
537 keywords are shown like <b>kword</b>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
538 and other terminal symbols are shown like ‘<b>=</b>’. |
380 | 539 The complete syntax of Luan can be found in <a href="#9">§9</a> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
540 at the end of this manual. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
541 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
542 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
543 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
544 <h3 <%=heading_options%> ><a name="lex">Lexical Conventions</a></h3> |
380 | 545 |
546 <p> | |
547 Luan ignores spaces and comments | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
548 between lexical elements (tokens), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
549 except as delimiters between names and keywords. |
380 | 550 Luan generally considers the end of a line to be the end of a statement. This catches errors and encourages readability. The exception to this is in paranthesis ( <i>(...)</i>, <i>[...]</i>, and <i>{...}</i> ) where the end of line is treated as white space. |
551 | |
552 <p> | |
553 <i>Names</i> | |
554 (also called <i>identifiers</i>) | |
555 in Luan can be any string of letters, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
556 digits, and underscores, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
557 not beginning with a digit. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
558 Identifiers are used to name variables, table fields, and labels. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
559 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
560 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
561 <p> |
380 | 562 The following <i>keywords</i> are reserved |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
563 and cannot be used as names: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
564 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
565 |
389 | 566 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
567 and break do else elseif end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
568 false for function goto if in |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
569 local nil not or repeat return |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
570 then true until while |
389 | 571 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
572 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
573 <p> |
380 | 574 Luan is a case-sensitive language: |
575 <tt>and</tt> is a reserved word, but <tt>And</tt> and <tt>AND</tt> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
576 are two different, valid names. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
577 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
578 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
579 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
580 The following strings denote other tokens: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
581 |
389 | 582 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
583 + - * / % ^ # |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
584 & ~ | << >> // |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
585 == ~= <= >= < > = |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
586 ( ) { } [ ] :: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
587 ; : , . .. ... |
389 | 588 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
589 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
590 <p> |
380 | 591 <i>Literal strings</i> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
592 can be delimited by matching single or double quotes, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
593 and can contain the following C-like escape sequences: |
380 | 594 '<tt>\a</tt>' (bell), |
595 '<tt>\b</tt>' (backspace), | |
596 '<tt>\f</tt>' (form feed), | |
597 '<tt>\n</tt>' (newline), | |
598 '<tt>\r</tt>' (carriage return), | |
599 '<tt>\t</tt>' (horizontal tab), | |
600 '<tt>\v</tt>' (vertical tab), | |
601 '<tt>\\</tt>' (backslash), | |
602 '<tt>\"</tt>' (quotation mark [double quote]), | |
603 and '<tt>\'</tt>' (apostrophe [single quote]). | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
604 A backslash followed by a real newline |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
605 results in a newline in the string. |
380 | 606 The escape sequence '<tt>\z</tt>' skips the following span |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
607 of white-space characters, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
608 including line breaks; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
609 it is particularly useful to break and indent a long literal string |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
610 into multiple lines without adding the newlines and spaces |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
611 into the string contents. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
612 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
613 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
614 <p> |
380 | 615 Luan can specify any character in a literal string by its numerical value. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
616 This can be done |
380 | 617 with the escape sequence <tt>\x<i>XX</i></tt>, |
618 where <i>XX</i> is a sequence of exactly two hexadecimal digits, | |
619 or with the escape sequence <tt>\<i>ddd</i></tt>, | |
620 where <i>ddd</i> is a sequence of up to three decimal digits. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
621 (Note that if a decimal escape sequence is to be followed by a digit, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
622 it must be expressed using exactly three digits.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
623 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
624 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
625 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
626 Literal strings can also be defined using a long format |
380 | 627 enclosed by <i>long brackets</i>. |
628 We define an <i>opening long bracket of level <i>n</i></i> as an opening | |
629 square bracket followed by <i>n</i> equal signs followed by another | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
630 opening square bracket. |
380 | 631 So, an opening long bracket of level 0 is written as <tt>[[</tt>, |
632 an opening long bracket of level 1 is written as <tt>[=[</tt>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
633 and so on. |
380 | 634 A <i>closing long bracket</i> is defined similarly; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
635 for instance, |
380 | 636 a closing long bracket of level 4 is written as <tt>]====]</tt>. |
637 A <i>long literal</i> starts with an opening long bracket of any level and | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
638 ends at the first closing long bracket of the same level. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
639 It can contain any text except a closing bracket of the same level. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
640 Literals in this bracketed form can run for several lines, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
641 do not interpret any escape sequences, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
642 and ignore long brackets of any other level. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
643 Any kind of end-of-line sequence |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
644 (carriage return, newline, carriage return followed by newline, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
645 or newline followed by carriage return) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
646 is converted to a simple newline. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
647 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
648 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
649 <p> |
380 | 650 Any character in a literal string not |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
651 explicitly affected by the previous rules represents itself. |
380 | 652 However, Luan opens files for parsing in text mode, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
653 and the system file functions may have problems with |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
654 some control characters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
655 So, it is safer to represent |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
656 non-text data as a quoted literal with |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
657 explicit escape sequences for non-text characters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
658 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
659 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
660 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
661 For convenience, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
662 when the opening long bracket is immediately followed by a newline, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
663 the newline is not included in the string. |
380 | 664 As an example |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
665 the five literal strings below denote the same string: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
666 |
389 | 667 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
668 a = 'alo\n123"' |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
669 a = "alo\n123\"" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
670 a = '\97lo\10\04923"' |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
671 a = [[alo |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
672 123"]] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
673 a = [==[ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
674 alo |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
675 123"]==] |
389 | 676 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
677 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
678 <p> |
380 | 679 A <i>numerical constant</i> (or <i>numeral</i>) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
680 can be written with an optional fractional part |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
681 and an optional decimal exponent, |
380 | 682 marked by a letter '<tt>e</tt>' or '<tt>E</tt>'. |
683 Luan also accepts hexadecimal constants, | |
684 which start with <tt>0x</tt> or <tt>0X</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
685 Hexadecimal constants also accept an optional fractional part |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
686 plus an optional binary exponent, |
380 | 687 marked by a letter '<tt>p</tt>' or '<tt>P</tt>'. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
688 A numeric constant with a fractional dot or an exponent |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
689 denotes a float; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
690 otherwise it denotes an integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
691 Examples of valid integer constants are |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
692 |
389 | 693 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
694 3 345 0xff 0xBEBADA |
389 | 695 </pre></tt></p> |
382 | 696 |
697 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
698 Examples of valid float constants are |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
699 |
389 | 700 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
701 3.0 3.1416 314.16e-2 0.31416E1 34e1 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
702 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1 |
389 | 703 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
704 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
705 <p> |
380 | 706 A <i>comment</i> starts with a double hyphen (<tt>--</tt>) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
707 anywhere outside a string. |
380 | 708 If the text immediately after <tt>--</tt> is not an opening long bracket, |
709 the comment is a <i>short comment</i>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
710 which runs until the end of the line. |
380 | 711 Otherwise, it is a <i>long comment</i>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
712 which runs until the corresponding closing long bracket. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
713 Long comments are frequently used to disable code temporarily. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
714 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
715 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
716 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
717 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
718 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
719 <h3 <%=heading_options%> ><a name="vars">Variables</a></h3> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
720 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
721 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
722 Variables are places that store values. |
380 | 723 There are three kinds of variables in Luan: |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
724 global variables, local variables, and table fields. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
725 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
726 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
727 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
728 A single name can denote a global variable or a local variable |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
729 (or a function's formal parameter, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
730 which is a particular kind of local variable): |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
731 |
389 | 732 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
733 var ::= Name |
389 | 734 </pre></tt></p> |
382 | 735 |
736 <p> | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
737 Name denotes identifiers, as defined in <a href="#lex">Lexical Conventions</a>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
738 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
739 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
740 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
741 Any variable name is assumed to be global unless explicitly declared |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
742 as a local (see <a href="#local_stmt">Local Declarations</a>). |
380 | 743 Local variables are <i>lexically scoped</i>: |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
744 local variables can be freely accessed by functions |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
745 defined inside their scope (see <a href="#visibility">Visibility Rules</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
746 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
747 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
748 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
749 Before the first assignment to a variable, its value is <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
750 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
751 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
752 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
753 Square brackets are used to index a table: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
754 |
389 | 755 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
756 var ::= prefixexp ‘<b>[</b>’ exp ‘<b>]</b>’ |
389 | 757 </pre></tt></p> |
382 | 758 |
759 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
760 The meaning of accesses to table fields can be changed via metatables. |
380 | 761 An access to an indexed variable <tt>t[i]</tt> is equivalent to |
762 a call <tt>gettable_event(t,i)</tt>. | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
763 (See <a href="#meta">Metatables and Metamethods</a> for a complete description of the |
380 | 764 <tt>gettable_event</tt> function. |
765 This function is not defined or callable in Luan. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
766 We use it here only for explanatory purposes.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
767 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
768 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
769 <p> |
380 | 770 The syntax <tt>var.Name</tt> is just syntactic sugar for |
771 <tt>var["Name"]</tt>: | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
772 |
389 | 773 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
774 var ::= prefixexp ‘<b>.</b>’ Name |
389 | 775 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
776 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
777 <p> |
380 | 778 An access to a global variable <tt>x</tt> |
779 is equivalent to <tt>_ENV.x</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
780 Due to the way that chunks are compiled, |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
781 <tt>_ENV</tt> is never a global name (see <a href="#env">Environments</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
782 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
783 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
784 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
785 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
786 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
787 <h3 <%=heading_options%> ><a name="stmts">Statements</a></h3> |
389 | 788 |
789 <p> | |
790 Luan supports an almost conventional set of statements, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
791 similar to those in Pascal or C. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
792 This set includes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
793 assignments, control structures, function calls, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
794 and variable declarations. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
795 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
796 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
797 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
798 <h4 <%=heading_options%> ><a name="blocks">Blocks</a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
799 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
800 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
801 A block is a list of statements, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
802 which are executed sequentially: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
803 |
389 | 804 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
805 block ::= {stat} |
389 | 806 </pre></tt></p> |
807 | |
808 <p> | |
809 Luan has <i>empty statements</i> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
810 that allow you to separate statements with semicolons, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
811 start a block with a semicolon |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
812 or write two semicolons in sequence: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
813 |
389 | 814 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
815 stat ::= ‘<b>;</b>’ |
389 | 816 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
817 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
818 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
819 A block can be explicitly delimited to produce a single statement: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
820 |
389 | 821 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
822 stat ::= <b>do</b> block <b>end</b> |
389 | 823 </pre></tt></p> |
824 | |
825 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
826 Explicit blocks are useful |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
827 to control the scope of variable declarations. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
828 Explicit blocks are also sometimes used to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
829 add a <b>return</b> statement in the middle |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
830 of another block (see <a href="#control">Control Structures</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
831 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
832 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
833 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
834 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
835 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
836 <h4 <%=heading_options%> ><a name="chunks">Chunks</a></h4> |
395 | 837 |
838 <p> | |
839 The unit of compilation of Luan is called a <i>chunk</i>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
840 Syntactically, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
841 a chunk is simply a block: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
842 |
395 | 843 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
844 chunk ::= block |
395 | 845 </pre></tt></p> |
846 | |
847 <p> | |
848 Luan handles a chunk as the body of an anonymous function | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
849 with a variable number of arguments |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
850 (see <a href="#fn_def">Function Definitions</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
851 As such, chunks can define local variables, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
852 receive arguments, and return values. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
853 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
854 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
855 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
856 A chunk can be stored in a file or in a string inside the host program. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
857 To execute a chunk, |
395 | 858 Luan first <i>loads</i> it, |
859 compiling the chunk's code, | |
860 and then Luan executes the compiled code. | |
861 | |
862 | |
863 | |
864 | |
865 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
866 <h4 <%=heading_options%> ><a name="assignment">Assignment</a></h4> |
395 | 867 |
868 <p> | |
869 Luan allows multiple assignments. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
870 Therefore, the syntax for assignment |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
871 defines a list of variables on the left side |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
872 and a list of expressions on the right side. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
873 The elements in both lists are separated by commas: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
874 |
395 | 875 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
876 stat ::= varlist ‘<b>=</b>’ explist |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
877 varlist ::= var {‘<b>,</b>’ var} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
878 explist ::= exp {‘<b>,</b>’ exp} |
395 | 879 </pre></tt></p> |
880 | |
881 <p> | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
882 Expressions are discussed in <a href="#expressions">Expressions</a>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
883 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
884 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
885 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
886 Before the assignment, |
395 | 887 the list of values is <i>adjusted</i> to the length of |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
888 the list of variables. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
889 If there are more values than needed, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
890 the excess values are thrown away. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
891 If there are fewer values than needed, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
892 the list is extended with as many <b>nil</b>'s as needed. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
893 If the list of expressions ends with a function call, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
894 then all values returned by that call enter the list of values, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
895 before the adjustment |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
896 (except when the call is enclosed in parentheses; see <a href="#expressions">Expressions</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
897 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
898 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
899 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
900 The assignment statement first evaluates all its expressions |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
901 and only then the assignments are performed. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
902 Thus the code |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
903 |
395 | 904 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
905 i = 3 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
906 i, a[i] = i+1, 20 |
395 | 907 </pre></tt></p> |
908 | |
909 <p> | |
910 sets <tt>a[3]</tt> to 20, without affecting <tt>a[4]</tt> | |
911 because the <tt>i</tt> in <tt>a[i]</tt> is evaluated (to 3) | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
912 before it is assigned 4. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
913 Similarly, the line |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
914 |
395 | 915 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
916 x, y = y, x |
395 | 917 </pre></tt></p> |
918 | |
919 <p> | |
920 exchanges the values of <tt>x</tt> and <tt>y</tt>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
921 and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
922 |
395 | 923 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
924 x, y, z = y, z, x |
395 | 925 </pre></tt></p> |
926 | |
927 <p> | |
928 cyclically permutes the values of <tt>x</tt>, <tt>y</tt>, and <tt>z</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
929 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
930 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
931 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
932 The meaning of assignments to global variables |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
933 and table fields can be changed via metatables. |
395 | 934 An assignment to an indexed variable <tt>t[i] = val</tt> is equivalent to |
935 <tt>settable_event(t,i,val)</tt>. | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
936 (See <a href="#meta">Metatables and Metamethods</a> for a complete description of the |
395 | 937 <tt>settable_event</tt> function. |
938 This function is not defined or callable in Luan. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
939 We use it here only for explanatory purposes.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
940 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
941 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
942 <p> |
395 | 943 An assignment to a global name <tt>x = val</tt> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
944 is equivalent to the assignment |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
945 <tt>_ENV.x = val</tt> (see <a href="#env">Environments</a>). |
395 | 946 |
947 | |
948 | |
949 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
950 <h4 <%=heading_options%> ><a name="control">Control Structures</a></h4> |
395 | 951 |
952 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
953 The control structures |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
954 <b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
955 familiar syntax: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
956 |
395 | 957 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
958 stat ::= <b>while</b> exp <b>do</b> block <b>end</b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
959 stat ::= <b>repeat</b> block <b>until</b> exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
960 stat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> |
395 | 961 </pre></tt></p> |
962 | |
963 <p> | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
964 Luan also has a <b>for</b> statement (see <a href="#for">For Statement</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
965 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
966 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
967 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
968 The condition expression of a |
395 | 969 control structure must be a boolean. |
970 Any other value type will produce an error. | |
971 This helps catch errors and makes code more readable. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
972 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
973 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
974 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
975 In the <b>repeat</b>–<b>until</b> loop, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
976 the inner block does not end at the <b>until</b> keyword, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
977 but only after the condition. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
978 So, the condition can refer to local variables |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
979 declared inside the loop block. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
980 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
981 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
982 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
983 The <b>break</b> statement terminates the execution of a |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
984 <b>while</b>, <b>repeat</b>, or <b>for</b> loop, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
985 skipping to the next statement after the loop: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
986 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
987 |
395 | 988 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
989 stat ::= <b>break</b> |
395 | 990 </pre></tt></p> |
991 | |
992 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
993 A <b>break</b> ends the innermost enclosing loop. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
994 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
995 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
996 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
997 The <b>return</b> statement is used to return values |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
998 from a function or a chunk |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
999 (which is an anonymous function). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1000 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1001 Functions can return more than one value, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1002 so the syntax for the <b>return</b> statement is |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1003 |
395 | 1004 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1005 stat ::= <b>return</b> [explist] [‘<b>;</b>’] |
395 | 1006 </pre></tt></p> |
1007 | |
1008 | |
1009 | |
1010 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1011 <h4 <%=heading_options%> ><a name="for">For Statement</a></h4> |
395 | 1012 |
1013 <p> | |
1014 The <b>for</b> statement works over functions, | |
1015 called <i>iterators</i>. | |
1016 On each iteration, the iterator function is called to produce a new value, | |
1017 stopping when this new value is <b>nil</b>. | |
1018 The <b>for</b> loop has the following syntax: | |
1019 | |
1020 <p><tt><pre> | |
1021 stat ::= <b>for</b> namelist <b>in</b> exp <b>do</b> block <b>end</b> | |
1022 namelist ::= Name {‘<b>,</b>’ Name} | |
1023 </pre></tt></p> | |
1024 | |
1025 <p> | |
1026 A <b>for</b> statement like | |
1027 | |
1028 <p><tt><pre> | |
1029 for <i>var_1</i>, ···, <i>var_n</i> in <i>exp</i> do <i>block</i> end | |
1030 </pre></tt></p> | |
1031 | |
1032 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1033 is equivalent to the code: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1034 |
395 | 1035 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1036 do |
395 | 1037 local <i>f</i> = <i>exp</i> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1038 while true do |
395 | 1039 local <i>var_1</i>, ···, <i>var_n</i> = <i>f</i>() |
1040 if <i>var_1</i> == nil then break end | |
1041 <i>block</i> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1042 end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1043 end |
395 | 1044 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1045 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1046 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1047 Note the following: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1048 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1049 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1050 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1051 <li> |
395 | 1052 <tt><i>exp</i></tt> is evaluated only once. |
1053 Its result is an <i>iterator</i> function. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1054 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1055 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1056 <li> |
395 | 1057 <tt><i>f</i></tt> is an invisible variable. |
1058 The name is here for explanatory purposes only. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1059 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1060 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1061 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1062 You can use <b>break</b> to exit a <b>for</b> loop. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1063 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1064 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1065 <li> |
395 | 1066 The loop variables <tt><i>var_i</i></tt> are local to the loop; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1067 you cannot use their values after the <b>for</b> ends. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1068 If you need these values, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1069 then assign them to other variables before breaking or exiting the loop. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1070 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1071 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1072 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1073 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1074 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1075 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1076 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1077 <h4 <%=heading_options%> ><a name="fn_stmt">Function Calls as Statements</a></h4> |
395 | 1078 |
1079 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1080 To allow possible side-effects, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1081 function calls can be executed as statements: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1082 |
395 | 1083 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1084 stat ::= functioncall |
395 | 1085 </pre></tt></p> |
1086 | |
1087 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1088 In this case, all returned values are thrown away. |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1089 Function calls are explained in <a href="#fn_calls">Function Calls</a>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1090 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1091 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1092 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1093 <h4 <%=heading_options%> ><a name="local_stmt">Local Declarations</a></h4> |
395 | 1094 |
1095 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1096 Local variables can be declared anywhere inside a block. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1097 The declaration can include an initial assignment: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1098 |
395 | 1099 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1100 stat ::= <b>local</b> namelist [‘<b>=</b>’ explist] |
395 | 1101 </pre></tt></p> |
1102 | |
1103 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1104 If present, an initial assignment has the same semantics |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1105 of a multiple assignment (see <a href="#assignment">Assignment</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1106 Otherwise, all variables are initialized with <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1107 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1108 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1109 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1110 A chunk is also a block (see <a href="#chunks">Chunks</a>), |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1111 and so local variables can be declared in a chunk outside any explicit block. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1112 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1113 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1114 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1115 The visibility rules for local variables are explained in <a href="#visibility">Visibility Rules</a>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1116 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1117 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1118 <h4 <%=heading_options%> ><a name="template_stmt">Template Statements</a></h4> |
465 | 1119 |
1120 <p>Template statements are based on <a href="#template_expr">template exressions</a> and provide the full equivalent of <a href="http://en.wikipedia.org/wiki/JavaServer_Pages">JSP</a> but in a general way. Template statements write the equivalent template exression to standard output. For example:</p> | |
1121 | |
1122 <p><tt><pre><%=Html.encode[[ | |
1123 local name = "Bob" | |
1124 %> | |
469 | 1125 Hello <%= name %>! |
1126 Bye <%= name %>. | |
465 | 1127 <% |
1128 ]]%></pre></tt></p> | |
1129 | |
1130 <p>is equivalent to the code:</p> | |
1131 | |
1132 <p><tt><pre><%=Html.encode[[ | |
1133 local name = "Bob" | |
1134 require("luan:Io").stdout.write( %> | |
469 | 1135 Hello <%= name %>! |
1136 Bye <%= name %>. | |
465 | 1137 <% ) |
1138 ]]%></pre></tt></p> | |
1139 | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1140 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1141 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1142 <h3 <%=heading_options%> ><a name="expressions">Expressions</a></h3> |
395 | 1143 |
1144 <p> | |
1145 The basic expressions in Luan are the following: | |
1146 | |
1147 <p><tt><pre> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1148 exp ::= prefixexp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1149 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1150 exp ::= Numeral |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1151 exp ::= LiteralString |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1152 exp ::= functiondef |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1153 exp ::= tableconstructor |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1154 exp ::= ‘<b>...</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1155 exp ::= exp binop exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1156 exp ::= unop exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1157 prefixexp ::= var | functioncall | ‘<b>(</b>’ exp ‘<b>)</b>’ |
395 | 1158 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1159 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1160 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1161 Numerals and literal strings are explained in <a href="#lex">Lexical Conventions</a>; |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1162 variables are explained in <a href="#vars">Variables</a>; |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1163 function definitions are explained in <a href="#fn_def">Function Definitions</a>; |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1164 function calls are explained in <a href="#fn_calls">Function Calls</a>; |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1165 table constructors are explained in <a href="#constructors">Table Constructors</a>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1166 Vararg expressions, |
395 | 1167 denoted by three dots ('<tt>...</tt>'), can only be used when |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1168 directly inside a vararg function; |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1169 they are explained in <a href="#fn_def">Function Definitions</a>. |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1170 |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1171 |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1172 <p> |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1173 Binary operators comprise arithmetic operators (see <a href="#arithmetic">Arithmetic Operators</a>), |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1174 relational operators (see <a href="#relational">Relational Operators</a>), logical operators (see <a href="#logical_ops">Logical Operators</a>), |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1175 and the concatenation operator (see <a href="#concatenation">Concatenation</a>). |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1176 Unary operators comprise the unary minus (see <a href="#arithmetic">Arithmetic Operators</a>), |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1177 the unary logical <b>not</b> (see <a href="#logical_ops">Logical Operators</a>), |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1178 and the unary <em>length operator</em> (see <a href="#length">The Length Operator</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1179 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1180 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1181 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1182 Both function calls and vararg expressions can result in multiple values. |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1183 If a function call is used as a statement (see <a href="#fn_stmt">Function Calls as Statements</a>), |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1184 then its return list is adjusted to zero elements, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1185 thus discarding all returned values. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1186 If an expression is used as the last (or the only) element |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1187 of a list of expressions, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1188 then no adjustment is made |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1189 (unless the expression is enclosed in parentheses). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1190 In all other contexts, |
395 | 1191 Luan adjusts the result list to one element, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1192 either discarding all values except the first one |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1193 or adding a single <b>nil</b> if there are no values. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1194 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1195 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1196 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1197 Here are some examples: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1198 |
395 | 1199 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1200 f() -- adjusted to 0 results |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1201 g(f(), x) -- f() is adjusted to 1 result |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1202 g(x, f()) -- g gets x plus all results from f() |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1203 a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1204 a,b = ... -- a gets the first vararg parameter, b gets |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1205 -- the second (both a and b can get nil if there |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1206 -- is no corresponding vararg parameter) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1207 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1208 a,b,c = x, f() -- f() is adjusted to 2 results |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1209 a,b,c = f() -- f() is adjusted to 3 results |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1210 return f() -- returns all results from f() |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1211 return ... -- returns all received vararg parameters |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1212 return x,y,f() -- returns x, y, and all results from f() |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1213 {f()} -- creates a list with all results from f() |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1214 {...} -- creates a list with all vararg parameters |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1215 {f(), nil} -- f() is adjusted to 1 result |
395 | 1216 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1217 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1218 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1219 Any expression enclosed in parentheses always results in only one value. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1220 Thus, |
395 | 1221 <tt>(f(x,y,z))</tt> is always a single value, |
1222 even if <tt>f</tt> returns several values. | |
1223 (The value of <tt>(f(x,y,z))</tt> is the first value returned by <tt>f</tt> | |
1224 or <b>nil</b> if <tt>f</tt> does not return any values.) | |
1225 | |
1226 | |
1227 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1228 <h4 <%=heading_options%> ><a name="arithmetic">Arithmetic Operators</a></h4> |
395 | 1229 |
1230 <p> | |
1231 Luan supports the following arithmetic operators: | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1232 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1233 <ul> |
395 | 1234 <li><b><tt>+</tt>: </b>addition</li> |
1235 <li><b><tt>-</tt>: </b>subtraction</li> | |
1236 <li><b><tt>*</tt>: </b>multiplication</li> | |
1237 <li><b><tt>/</tt>: </b>division</li> | |
1238 <li><b><tt>%</tt>: </b>modulo</li> | |
1239 <li><b><tt>^</tt>: </b>exponentiation</li> | |
1240 <li><b><tt>-</tt>: </b>unary minus</li> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1241 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1242 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1243 <p> |
395 | 1244 Addition, subtraction, multiplication, division, and unary minus are the same as these operators in Java. Exponentiation uses Java's <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#pow(double,%20double)">Math.pow</a> function. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1245 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1246 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1247 Modulo is defined as the remainder of a division |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1248 that rounds the quotient towards minus infinite (floor division). |
395 | 1249 (The Java modulo operator is not used.) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1250 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1251 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1252 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1253 <h4 <%=heading_options%> ><a name="conversions">Coercions and Conversions</a></h4> |
396 | 1254 |
1255 <p> | |
465 | 1256 Luan generally avoids automatic conversions. |
1257 String concatenation automatically converts all of its arguments to strings. | |
1258 | |
1259 <p> | |
1260 Luan provides library functions for explicit type conversions. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1261 |
396 | 1262 |
1263 | |
1264 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1265 <h4 <%=heading_options%> ><a name="relational">Relational Operators</a></h4> |
396 | 1266 |
1267 <p> | |
1268 Luan supports the following relational operators: | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1269 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1270 <ul> |
396 | 1271 <li><b><tt>==</tt>: </b>equality</li> |
1272 <li><b><tt>~=</tt>: </b>inequality</li> | |
1273 <li><b><tt><</tt>: </b>less than</li> | |
1274 <li><b><tt>></tt>: </b>greater than</li> | |
1275 <li><b><tt><=</tt>: </b>less or equal</li> | |
1276 <li><b><tt>>=</tt>: </b>greater or equal</li> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1277 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1278 These operators always result in <b>false</b> or <b>true</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1279 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1280 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1281 <p> |
396 | 1282 Equality (<tt>==</tt>) first compares the type of its operands. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1283 If the types are different, then the result is <b>false</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1284 Otherwise, the values of the operands are compared. |
396 | 1285 Strings, numbers, and binary values are compared in the obvious way (by value). |
1286 | |
1287 <p> | |
1288 Tables | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1289 are compared by reference: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1290 two objects are considered equal only if they are the same object. |
396 | 1291 Every time you create a new table, |
1292 it is different from any previously existing table. | |
1293 Closures are also compared by reference. | |
1294 | |
1295 <p> | |
417 | 1296 You can change the way that Luan compares tables |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1297 by using the "eq" metamethod (see <a href="#meta">Metatables and Metamethods</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1298 |
396 | 1299 <p> |
1300 Userdata are Java objects. They are compared for equality with the Java <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)"><tt>equals</tt></a> method. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1301 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1302 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1303 Equality comparisons do not convert strings to numbers |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1304 or vice versa. |
396 | 1305 Thus, <tt>"0"==0</tt> evaluates to <b>false</b>, |
1306 and <tt>t[0]</tt> and <tt>t["0"]</tt> denote different | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1307 entries in a table. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1308 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1309 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1310 <p> |
396 | 1311 The operator <tt>~=</tt> is exactly the negation of equality (<tt>==</tt>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1312 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1313 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1314 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1315 The order operators work as follows. |
396 | 1316 |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1317 If both arguments are numbers, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1318 then they are compared following |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1319 the usual rule for binary operations. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1320 Otherwise, if both arguments are strings, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1321 then their values are compared according to the current locale. |
396 | 1322 Otherwise, Luan tries to call the "lt" or the "le" |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1323 metamethod (see <a href="#meta">Metatables and Metamethods</a>). |
396 | 1324 A comparison <tt>a > b</tt> is translated to <tt>b < a</tt> |
1325 and <tt>a >= b</tt> is translated to <tt>b <= a</tt>. | |
1326 | |
1327 | |
1328 | |
1329 | |
1330 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1331 <h4 <%=heading_options%> ><a name="logical_ops">Logical Operators</a></h4> |
396 | 1332 |
1333 <p> | |
1334 The logical operators in Luan are | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1335 <b>and</b>, <b>or</b>, and <b>not</b>. |
396 | 1336 The <b>and</b> and <b>or</b> operators consider both <b>false</b> and <b>nil</b> as false |
1337 and anything else as true. | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1338 Like the control structures (see <a href="#control">Control Structures</a>), |
396 | 1339 the <b>not</b> operator requires a boolean value. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1340 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1341 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1342 The negation operator <b>not</b> always returns <b>false</b> or <b>true</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1343 The conjunction operator <b>and</b> returns its first argument |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1344 if this value is <b>false</b> or <b>nil</b>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1345 otherwise, <b>and</b> returns its second argument. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1346 The disjunction operator <b>or</b> returns its first argument |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1347 if this value is different from <b>nil</b> and <b>false</b>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1348 otherwise, <b>or</b> returns its second argument. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1349 Both <b>and</b> and <b>or</b> use short-circuit evaluation; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1350 that is, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1351 the second operand is evaluated only if necessary. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1352 Here are some examples: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1353 |
396 | 1354 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1355 10 or 20 --> 10 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1356 10 or error() --> 10 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1357 nil or "a" --> "a" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1358 nil and 10 --> nil |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1359 false and error() --> false |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1360 false and nil --> false |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1361 false or nil --> nil |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1362 10 and 20 --> 20 |
396 | 1363 </pre></tt></p> |
1364 | |
1365 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1366 (In this manual, |
396 | 1367 <tt>--></tt> indicates the result of the preceding expression.) |
1368 | |
1369 | |
1370 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1371 <h4 <%=heading_options%> ><a name="concatenation">Concatenation</a></h4> |
396 | 1372 |
1373 <p> | |
1374 The string concatenation operator in Luan is | |
1375 denoted by two dots ('<tt>..</tt>'). | |
1376 All operands are converted to strings. | |
1377 | |
1378 | |
1379 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1380 <h4 <%=heading_options%> ><a name="length">The Length Operator</a></h4> |
396 | 1381 |
1382 <p> | |
1383 The length operator is denoted by the unary prefix operator <tt>#</tt>. | |
1384 The length of a string is its number of characters. | |
1385 The length of a binary is its number of bytes. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1386 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1387 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1388 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1389 A program can modify the behavior of the length operator for |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1390 any table through the <tt>__len</tt> metamethod (see <a href="#meta">Metatables and Metamethods</a>). |
396 | 1391 |
1392 | |
1393 <p> | |
1394 Unless a <tt>__len</tt> metamethod is given, | |
1395 the length of a table <tt>t</tt> is defined | |
1396 as the number of elements in <em>sequence</em>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1397 that is, |
396 | 1398 the size of the set of its positive numeric keys is equal to <em>{1..n}</em> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1399 for some non-negative integer <em>n</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1400 In that case, <em>n</em> is its length. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1401 Note that a table like |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1402 |
396 | 1403 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1404 {10, 20, nil, 40} |
396 | 1405 </pre></tt></p> |
1406 | |
1407 <p> | |
1408 has a length of <tt>2</tt>, because that is the last key in sequence. | |
1409 | |
1410 | |
1411 | |
1412 | |
1413 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1414 <h4 <%=heading_options%> ><a name="precedence">Precedence</a></h4> |
396 | 1415 |
1416 <p> | |
1417 Operator precedence in Luan follows the table below, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1418 from lower to higher priority: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1419 |
396 | 1420 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1421 or |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1422 and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1423 < > <= >= ~= == |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1424 .. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1425 + - |
396 | 1426 * / % |
1427 unary operators (not # -) | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1428 ^ |
396 | 1429 </pre></tt></p> |
1430 | |
1431 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1432 As usual, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1433 you can use parentheses to change the precedences of an expression. |
396 | 1434 The concatenation ('<tt>..</tt>') and exponentiation ('<tt>^</tt>') |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1435 operators are right associative. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1436 All other binary operators are left associative. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1437 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1438 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1439 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1440 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1441 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1442 <h4 <%=heading_options%> ><a name="constructors">Table Constructors</a></h4> |
396 | 1443 |
1444 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1445 Table constructors are expressions that create tables. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1446 Every time a constructor is evaluated, a new table is created. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1447 A constructor can be used to create an empty table |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1448 or to create a table and initialize some of its fields. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1449 The general syntax for constructors is |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1450 |
396 | 1451 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1452 tableconstructor ::= ‘<b>{</b>’ [fieldlist] ‘<b>}</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1453 fieldlist ::= field {fieldsep field} [fieldsep] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1454 field ::= ‘<b>[</b>’ exp ‘<b>]</b>’ ‘<b>=</b>’ exp | Name ‘<b>=</b>’ exp | exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1455 fieldsep ::= ‘<b>,</b>’ | ‘<b>;</b>’ |
396 | 1456 </pre></tt></p> |
1457 | |
1458 <p> | |
1459 Each field of the form <tt>[exp1] = exp2</tt> adds to the new table an entry | |
1460 with key <tt>exp1</tt> and value <tt>exp2</tt>. | |
1461 A field of the form <tt>name = exp</tt> is equivalent to | |
1462 <tt>["name"] = exp</tt>. | |
1463 Finally, fields of the form <tt>exp</tt> are equivalent to | |
1464 <tt>[i] = exp</tt>, where <tt>i</tt> are consecutive integers | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1465 starting with 1. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1466 Fields in the other formats do not affect this counting. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1467 For example, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1468 |
396 | 1469 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1470 a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } |
396 | 1471 </pre></tt></p> |
1472 | |
1473 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1474 is equivalent to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1475 |
396 | 1476 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1477 do |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1478 local t = {} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1479 t[f(1)] = g |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1480 t[1] = "x" -- 1st exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1481 t[2] = "y" -- 2nd exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1482 t.x = 1 -- t["x"] = 1 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1483 t[3] = f(x) -- 3rd exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1484 t[30] = 23 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1485 t[4] = 45 -- 4th exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1486 a = t |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1487 end |
396 | 1488 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1489 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1490 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1491 The order of the assignments in a constructor is undefined. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1492 (This order would be relevant only when there are repeated keys.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1493 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1494 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1495 <p> |
396 | 1496 If the last field in the list has the form <tt>exp</tt> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1497 and the expression is a function call or a vararg expression, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1498 then all values returned by this expression enter the list consecutively |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1499 (see <a href="#fn_calls">Function Calls</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1500 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1501 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1502 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1503 The field list can have an optional trailing separator, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1504 as a convenience for machine-generated code. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1505 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1506 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1507 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1508 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1509 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1510 <h4 <%=heading_options%> ><a name="fn_calls">Function Calls</a></h4> |
417 | 1511 |
1512 <p> | |
1513 A function call in Luan has the following syntax: | |
1514 | |
1515 <p><tt><pre> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1516 functioncall ::= prefixexp args |
417 | 1517 </pre></tt></p> |
1518 | |
1519 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1520 In a function call, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1521 first prefixexp and args are evaluated. |
417 | 1522 If the value of prefixexp has type <i>function</i>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1523 then this function is called |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1524 with the given arguments. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1525 Otherwise, the prefixexp "call" metamethod is called, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1526 having as first parameter the value of prefixexp, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1527 followed by the original call arguments |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1528 (see <a href="#meta">Metatables and Metamethods</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1529 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1530 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1531 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1532 Arguments have the following syntax: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1533 |
417 | 1534 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1535 args ::= ‘<b>(</b>’ [explist] ‘<b>)</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1536 args ::= tableconstructor |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1537 args ::= LiteralString |
417 | 1538 </pre></tt></p> |
1539 | |
1540 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1541 All argument expressions are evaluated before the call. |
417 | 1542 A call of the form <tt>f{<i>fields</i>}</tt> is |
1543 syntactic sugar for <tt>f({<i>fields</i>})</tt>; | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1544 that is, the argument list is a single new table. |
417 | 1545 A call of the form <tt>f'<i>string</i>'</tt> |
1546 (or <tt>f"<i>string</i>"</tt> or <tt>f[[<i>string</i>]]</tt>) | |
1547 is syntactic sugar for <tt>f('<i>string</i>')</tt>; | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1548 that is, the argument list is a single literal string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1549 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1550 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1551 <p> |
417 | 1552 A call of the form <tt>return <i>functioncall</i></tt> is called |
1553 a <i>tail call</i>. | |
1554 Luan implements <i>proper tail calls</i> | |
1555 (or <i>proper tail recursion</i>): | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1556 in a tail call, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1557 the called function reuses the stack entry of the calling function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1558 Therefore, there is no limit on the number of nested tail calls that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1559 a program can execute. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1560 However, a tail call erases any debug information about the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1561 calling function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1562 Note that a tail call only happens with a particular syntax, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1563 where the <b>return</b> has one single function call as argument; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1564 this syntax makes the calling function return exactly |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1565 the returns of the called function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1566 So, none of the following examples are tail calls: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1567 |
417 | 1568 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1569 return (f(x)) -- results adjusted to 1 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1570 return 2 * f(x) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1571 return x, f(x) -- additional results |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1572 f(x); return -- results discarded |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1573 return x or f(x) -- results adjusted to 1 |
417 | 1574 </pre></tt></p> |
1575 | |
1576 | |
1577 | |
1578 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1579 <h4 <%=heading_options%> ><a name="fn_def">Function Definitions</a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1580 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1581 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1582 The syntax for function definition is |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1583 |
417 | 1584 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1585 functiondef ::= <b>function</b> funcbody |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1586 funcbody ::= ‘<b>(</b>’ [parlist] ‘<b>)</b>’ block <b>end</b> |
417 | 1587 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1588 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1589 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1590 The following syntactic sugar simplifies function definitions: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1591 |
417 | 1592 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1593 stat ::= <b>function</b> funcname funcbody |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1594 stat ::= <b>local</b> <b>function</b> Name funcbody |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1595 funcname ::= Name {‘<b>.</b>’ Name} [‘<b>:</b>’ Name] |
417 | 1596 </pre></tt></p> |
1597 | |
1598 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1599 The statement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1600 |
417 | 1601 <p><tt><pre> |
1602 function f () <i>body</i> end | |
1603 </pre></tt></p> | |
1604 | |
1605 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1606 translates to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1607 |
417 | 1608 <p><tt><pre> |
1609 f = function () <i>body</i> end | |
1610 </pre></tt></p> | |
1611 | |
1612 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1613 The statement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1614 |
417 | 1615 <p><tt><pre> |
1616 function t.a.b.c.f () <i>body</i> end | |
1617 </pre></tt></p> | |
1618 | |
1619 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1620 translates to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1621 |
417 | 1622 <p><tt><pre> |
1623 t.a.b.c.f = function () <i>body</i> end | |
1624 </pre></tt></p> | |
1625 | |
1626 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1627 The statement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1628 |
417 | 1629 <p><tt><pre> |
1630 local function f () <i>body</i> end | |
1631 </pre></tt></p> | |
1632 | |
1633 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1634 translates to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1635 |
417 | 1636 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1637 local f; f = function () <em>body</em> end |
417 | 1638 </pre></tt></p> |
1639 | |
1640 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1641 not to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1642 |
417 | 1643 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1644 local f = function () <em>body</em> end |
417 | 1645 </pre></tt></p> |
1646 | |
1647 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1648 (This only makes a difference when the body of the function |
417 | 1649 contains references to <tt>f</tt>.) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1650 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1651 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1652 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1653 A function definition is an executable expression, |
417 | 1654 whose value has type <i>function</i>. |
1655 When Luan precompiles a chunk, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1656 all its function bodies are precompiled too. |
417 | 1657 Then, whenever Luan executes the function definition, |
1658 the function is <i>instantiated</i> (or <i>closed</i>). | |
1659 This function instance (or <i>closure</i>) | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1660 is the final value of the expression. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1661 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1662 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1663 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1664 Parameters act as local variables that are |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1665 initialized with the argument values: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1666 |
417 | 1667 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1668 parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’ |
417 | 1669 </pre></tt></p> |
1670 | |
1671 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1672 When a function is called, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1673 the list of arguments is adjusted to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1674 the length of the list of parameters, |
417 | 1675 unless the function is a <i>vararg function</i>, |
1676 which is indicated by three dots ('<tt>...</tt>') | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1677 at the end of its parameter list. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1678 A vararg function does not adjust its argument list; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1679 instead, it collects all extra arguments and supplies them |
417 | 1680 to the function through a <i>vararg expression</i>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1681 which is also written as three dots. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1682 The value of this expression is a list of all actual extra arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1683 similar to a function with multiple results. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1684 If a vararg expression is used inside another expression |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1685 or in the middle of a list of expressions, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1686 then its return list is adjusted to one element. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1687 If the expression is used as the last element of a list of expressions, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1688 then no adjustment is made |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1689 (unless that last expression is enclosed in parentheses). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1690 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1691 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1692 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1693 As an example, consider the following definitions: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1694 |
417 | 1695 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1696 function f(a, b) end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1697 function g(a, b, ...) end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1698 function r() return 1,2,3 end |
417 | 1699 </pre></tt></p> |
1700 | |
1701 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1702 Then, we have the following mapping from arguments to parameters and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1703 to the vararg expression: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1704 |
417 | 1705 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1706 CALL PARAMETERS |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1707 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1708 f(3) a=3, b=nil |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1709 f(3, 4) a=3, b=4 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1710 f(3, 4, 5) a=3, b=4 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1711 f(r(), 10) a=1, b=10 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1712 f(r()) a=1, b=2 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1713 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1714 g(3) a=3, b=nil, ... --> (nothing) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1715 g(3, 4) a=3, b=4, ... --> (nothing) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1716 g(3, 4, 5, 8) a=3, b=4, ... --> 5 8 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1717 g(5, r()) a=5, b=1, ... --> 2 3 |
417 | 1718 </pre></tt></p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1719 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1720 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1721 Results are returned using the <b>return</b> statement (see <a href="#control">Control Structures</a>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1722 If control reaches the end of a function |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1723 without encountering a <b>return</b> statement, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1724 then the function returns with no results. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1725 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1726 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1727 <h4 <%=heading_options%> ><a name="template_expr">Template Expressions</a></h4> |
465 | 1728 |
1729 <p>Luan template expression are based on <a href="http://en.wikipedia.org/wiki/JavaServer_Pages">JSP</a>. Template expressions return multiple values. Here is an example:</p> | |
1730 | |
1731 <p><tt><pre><%=Html.encode[[ | |
1732 local name = "Bob" | |
469 | 1733 write( %>Hello <%= name %>!<% ) |
465 | 1734 ]]%></pre></tt></p> |
1735 | |
1736 <p>This is equivalent to the code:</p> | |
1737 | |
1738 <p><tt><pre> | |
1739 local name = "Bob" | |
1740 write( "Hello ", name, "!" ) | |
1741 </pre></tt></p> | |
1742 | |
1743 <p>The strings in template expressions may be multiple lines.</p> | |
1744 | |
417 | 1745 |
1746 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1747 <h3 <%=heading_options%> ><a name="visibility">Visibility Rules</a></h3> |
417 | 1748 |
1749 <p> | |
1750 Luan is a lexically scoped language. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1751 The scope of a local variable begins at the first statement after |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1752 its declaration and lasts until the last non-void statement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1753 of the innermost block that includes the declaration. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1754 Consider the following example: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1755 |
417 | 1756 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1757 x = 10 -- global variable |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1758 do -- new block |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1759 local x = x -- new 'x', with value 10 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1760 print(x) --> 10 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1761 x = x+1 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1762 do -- another block |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1763 local x = x+1 -- another 'x' |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1764 print(x) --> 12 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1765 end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1766 print(x) --> 11 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1767 end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1768 print(x) --> 10 (the global one) |
417 | 1769 </pre></tt></p> |
1770 | |
1771 <p> | |
1772 Notice that, in a declaration like <tt>local x = x</tt>, | |
1773 the new <tt>x</tt> being declared is not in scope yet, | |
1774 and so the second <tt>x</tt> refers to the outside variable. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1775 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1776 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1777 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1778 Because of the lexical scoping rules, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1779 local variables can be freely accessed by functions |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1780 defined inside their scope. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1781 A local variable used by an inner function is called |
417 | 1782 an <i>upvalue</i>, or <i>external local variable</i>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1783 inside the inner function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1784 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1785 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1786 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1787 Notice that each execution of a <b>local</b> statement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1788 defines new local variables. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1789 Consider the following example: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1790 |
417 | 1791 <p><tt><pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1792 a = {} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1793 local x = 20 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1794 for i=1,10 do |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1795 local y = 0 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1796 a[i] = function () y=y+1; return x+y end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1797 end |
417 | 1798 </pre></tt></p> |
1799 | |
1800 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1801 The loop creates ten closures |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1802 (that is, ten instances of the anonymous function). |
417 | 1803 Each of these closures uses a different <tt>y</tt> variable, |
1804 while all of them share the same <tt>x</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1805 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1806 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1807 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1808 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1809 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1810 <h2 <%=heading_options%> ><a name="libs">Standard Libraries</a></h2> |
468 | 1811 |
1812 <p> | |
1813 The standard Luan libraries provide useful functions | |
1814 that are implemented both in Java and in Luan itself. | |
1815 How each function is implemented shouldn't matter to the user. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1816 Some of these functions provide essential services to the language |
478 | 1817 (e.g., <a href="#Luan.type"><tt>type</tt></a> and <a href="#Luan.get_metatable"><tt>get_metatable</tt></a>); |
468 | 1818 others provide access to "outside" services (e.g., I/O). |
1819 | |
1820 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1821 <h3 <%=heading_options%> ><a name="default_lib">Default Environment</a></h3> |
468 | 1822 |
1823 <p> | |
1824 These are provided by default as local variables for any Luan code as described in <a href="#env">Environments</a>. | |
1825 | |
470 | 1826 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1827 <h4 <%=heading_options%> ><a name="_ENV"><tt>_ENV</tt></a></h4> |
468 | 1828 |
1829 <p> | |
1830 This is a table that holds the global variables of a module as described in <a href="#env">Environments</a>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1831 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1832 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1833 <h4 <%=heading_options%> ><a name="require"><tt>java ()</tt></a></h4> |
470 | 1834 |
1835 <p> | |
1836 This function enables Java in the current chunk if that chunk has permission to use Java. If the chunk doesn't have permission to use Java, then an error is thrown. | |
1837 | |
1838 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1839 <h4 <%=heading_options%> ><a name="require"><tt>require (mod_uri)</tt></a></h4> |
470 | 1840 |
1841 <p> | |
1842 Example use: | |
1843 | |
1844 <p><tt><pre> | |
1845 local Table = require "luan:Table" | |
1846 </pre></tt></p> | |
1847 | |
1848 <p> | |
1849 Could be defined as: | |
1850 | |
1851 <p><tt><pre> | |
1852 local function require(mod_name) | |
476 | 1853 return <a href="#Package.load">Package.load</a>(mod_name) or <a href="#Luan.error">Luan.error</a>("module '"..mod_name.."' not found") |
470 | 1854 end |
1855 </pre></tt></p> | |
1856 | |
1857 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1858 <h3 <%=heading_options%> ><a name="luan_lib">Basic Functions</a></h3> |
470 | 1859 |
1860 <p> | |
1861 Include this library by: | |
1862 | |
1863 <p><tt><pre> | |
1864 local Luan = require "luan:Luan" | |
1865 </pre></tt></p> | |
1866 | |
476 | 1867 <p> |
470 | 1868 The basic library provides basic functions to Luan that don't depend on other libaries. |
1869 | |
1870 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1871 <h4 <%=heading_options%> ><a name="Luan.assert"><tt>Luan.assert (v [, message])</tt></a></h4> |
470 | 1872 |
1873 <p> | |
1874 Could be defined as: | |
1875 | |
1876 <p><tt><pre> | |
1877 function Luan.assert(v,message) | |
472 | 1878 return v or <a href="#Luan.error">Luan.error</a>(message or "assertion failed!") |
470 | 1879 end |
1880 </pre></tt></p> | |
1881 | |
1882 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1883 <h4 <%=heading_options%> ><a name="Luan.assert_binary"><tt>Luan.assert_binary (v)</tt></a></h4> |
470 | 1884 |
1885 <p> | |
1886 Could be defined as: | |
1887 | |
1888 <p><tt><pre> | |
1889 function Luan.assert_binary(v) | |
1890 local v_type = Luan.type(v) | |
472 | 1891 return v_type == "binary" and v or <a href="#Luan.error">Luan.error</a>("bad argument #1 (binary expected, got "..v_type..")") |
470 | 1892 end |
1893 </pre></tt></p> | |
1894 | |
1895 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1896 <h4 <%=heading_options%> ><a name="Luan.assert_boolean"><tt>Luan.assert_boolean (v)</tt></a></h4> |
470 | 1897 |
1898 <p> | |
1899 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>boolean</tt>. | |
1900 | |
1901 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1902 <h4 <%=heading_options%> ><a name="Luan.assert_integer"><tt>Luan.assert_integer (v)</tt></a></h4> |
470 | 1903 |
1904 <p> | |
1905 Asserts that <tt>v</tt> can be converted to Java type <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html">Integer</a> and returns an Integer. | |
1906 | |
1907 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1908 <h4 <%=heading_options%> ><a name="Luan.assert_long"><tt>Luan.assert_long (v)</tt></a></h4> |
470 | 1909 |
1910 <p> | |
1911 Asserts that <tt>v</tt> can be converted to Java type <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html">Long</a> and returns a Long. | |
1912 | |
1913 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1914 <h4 <%=heading_options%> ><a name="Luan.assert_number"><tt>Luan.assert_number (v)</tt></a></h4> |
470 | 1915 |
1916 <p> | |
1917 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>number</tt>. | |
1918 | |
1919 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1920 <h4 <%=heading_options%> ><a name="Luan.assert_string"><tt>Luan.assert_string (v)</tt></a></h4> |
470 | 1921 |
1922 <p> | |
1923 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>string</tt>. | |
1924 | |
1925 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1926 <h4 <%=heading_options%> ><a name="Luan.assert_table"><tt>Luan.assert_table (v)</tt></a></h4> |
470 | 1927 |
1928 <p> | |
1929 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>table</tt>. | |
1930 | |
1931 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1932 <h4 <%=heading_options%> ><a name="Luan.do_file"><tt>Luan.do_file ([uri])</tt></a></h4> |
470 | 1933 |
1934 <p> | |
1935 Could be defined as: | |
1936 | |
1937 <p><tt><pre> | |
1938 function Luan.do_file(uri) | |
474 | 1939 return <a href="#Luan.load_file">Luan.load_file</a>(uri)() |
470 | 1940 end |
1941 </pre></tt></p> | |
1942 | |
1943 | |
1944 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1945 <h4 <%=heading_options%> ><a name="Luan.error"><tt>Luan.error (message)</tt></a></h4> |
470 | 1946 |
1947 <p> | |
482 | 1948 Throws an error containing the message. |
1949 | |
1950 <p> | |
1951 Could be defined as: | |
1952 | |
1953 <p><tt><pre> | |
1954 function Luan.error(message) | |
1955 <a href="#Luan.new_error">Luan.new_error</a>(message).throw() | |
1956 end | |
1957 </pre></tt></p> | |
1958 | |
470 | 1959 |
1960 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1961 <h4 <%=heading_options%> ><a name="Luan.get_metatable"><tt>Luan.get_metatable (table)</tt></a></h4> |
470 | 1962 |
1963 <p> | |
1964 If <tt>table</tt> does not have a metatable, returns <b>nil</b>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1965 Otherwise, |
470 | 1966 if the table's metatable has a <tt>"__metatable"</tt> field, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1967 returns the associated value. |
470 | 1968 Otherwise, returns the metatable of the given table. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1969 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1970 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
1971 <h4 <%=heading_options%> ><a name="Luan.ipairs"><tt>Luan.ipairs (t)</tt></a></h4> |
474 | 1972 |
1973 <p> | |
1974 Returns an iterator function | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1975 so that the construction |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1976 |
474 | 1977 <p><tt><pre> |
1978 for i,v in ipairs(t) do <i>body</i> end | |
1979 </pre></tt></p> | |
1980 | |
1981 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1982 will iterate over the key–value pairs |
474 | 1983 (<tt>1,t[1]</tt>), (<tt>2,t[2]</tt>), ..., |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1984 up to the first nil value. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1985 |
474 | 1986 <p> |
1987 Could be defined as: | |
1988 | |
1989 <p><tt><pre> | |
1990 function Luan.ipairs(t) | |
1991 local i = 0 | |
1992 return function() | |
1993 if i < #t then | |
1994 i = i + 1 | |
1995 return i, t[i] | |
1996 end | |
1997 end | |
1998 end | |
1999 </pre></tt></p> | |
2000 | |
2001 | |
2002 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2003 <h4 <%=heading_options%> ><a name="Luan.load"><tt>Luan.load (text, source_name [env, [, allow_expression]])</tt></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2004 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2005 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2006 Loads a chunk. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2007 |
474 | 2008 <p> |
2009 The <tt>text</tt> is compiled. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2010 If there are no syntactic errors, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2011 returns the compiled chunk as a function; |
474 | 2012 otherwise, throws an error. |
2013 | |
2014 <p> | |
2015 The <tt>source_name</tt> parameter is a string saying where the text came from. It is used to produce error messages. | |
2016 | |
2017 <p> | |
2018 If the <tt>env</tt> parameter is supplied, it becomes the <tt>_ENV</tt> of the chunk. | |
2019 | |
2020 <p> | |
2021 If the <tt>allow_expression</tt> parameter is <tt>true</tt> then the entire text can be nothing more than an expression in which case the chunk returns the value of this expression. | |
2022 | |
2023 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2024 <h4 <%=heading_options%> ><a name="Luan.load_file"><tt>Luan.load_file (file_uri [, add_extension])</tt></a></h4> |
474 | 2025 |
2026 <p> | |
2027 Similar to <a href="#Luan.load"><tt>load</tt></a>, | |
2028 but gets the chunk from file <tt>file_uri</tt> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2029 or from the standard input, |
474 | 2030 if no file uri is given. |
2031 | |
2032 <p> | |
2033 Could be defined as: | |
2034 | |
2035 <p><tt><pre> | |
2036 function Luan.load_file(file_uri,add_extension) | |
2037 file_uri = file_uri or "stdin:" | |
2038 local f = Io.uri(file_uri,add_extension) | |
2039 f.exists() or <a href="#Luan.error">Luan.error</a>("file '"..file_uri.."' not found") | |
2040 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri ) | |
2041 end | |
2042 </pre></tt></p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2043 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2044 |
482 | 2045 <h4 <%=heading_options%> ><a name="Luan.new_error"><tt>Luan.new_error (message)</tt></a></h4> |
2046 | |
2047 <p> | |
2048 Creates a new error table containing the message assigned to "<tt>message</tt>". The error table also contains a <tt>throw</tt> function which throws the error. The table also contains a list of stack trace elements where each stack trace element is a table containing "<tt>source</tt>", "<tt>line</tt>", and possible "<tt>call_to</tt>". The table also has a metatable containing "<tt>__to_string</tt>" to render the error. | |
2049 | |
2050 <p> | |
2051 To print the current stack trace, you could do: | |
2052 | |
2053 <p><tt><pre> | |
2054 Io.print( Luan.new_error "stack" ) | |
2055 </pre></tt></p> | |
2056 | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2057 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2058 <h4 <%=heading_options%> ><a name="Luan.pairs"><tt>Luan.pairs (t)</tt></a></h4> |
475 | 2059 |
2060 <p> | |
2061 If <tt>t</tt> has a metamethod <tt>__pairs</tt>, | |
2062 calls it with <tt>t</tt> as argument and returns the | |
2063 result from the call. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2064 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2065 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2066 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2067 Otherwise, |
475 | 2068 returns a function |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2069 so that the construction |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2070 |
475 | 2071 <p><tt><pre> |
2072 for k,v in pairs(t) do <i>body</i> end | |
2073 </pre></tt></p> | |
2074 | |
2075 <p> | |
2076 will iterate over all key–value pairs of table <tt>t</tt>. | |
2077 | |
2078 | |
2079 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2080 <h4 <%=heading_options%> ><a name="Luan.pcall"><tt>Luan.pcall (f [, arg1, ···])</tt></a></h4> |
475 | 2081 |
2082 <p> | |
2083 Calls function <tt>f</tt> with | |
2084 the given arguments in <i>protected mode</i>. | |
2085 This means that any error inside <tt>f</tt> is not propagated; | |
2086 instead, <tt>pcall</tt> catches the error | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2087 and returns a status code. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2088 Its first result is the status code (a boolean), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2089 which is true if the call succeeds without errors. |
475 | 2090 In such case, <tt>pcall</tt> also returns all results from the call, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2091 after this first result. |
475 | 2092 In case of any error, <tt>pcall</tt> returns <b>false</b> plus the error. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2093 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2094 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2095 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2096 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2097 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2098 <hr><h3><a name="pdf-print"><code>print (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2099 Receives any number of arguments |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2100 and prints their values to <code>stdout</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2101 using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert each argument to a string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2102 <code>print</code> is not intended for formatted output, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2103 but only as a quick way to show a value, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2104 for instance for debugging. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2105 For complete control over the output, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2106 use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>io.write</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2107 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2108 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2109 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2110 <h4 <%=heading_options%> ><a name="Luan.range"><tt>Luan.range (start, stop [, step])</tt></a></h4> |
476 | 2111 |
2112 <p> | |
2113 Based on <a href="https://docs.python.org/2/library/functions.html#range">the Python range() function</a>, this lets one iterate through a sequence of numbers. | |
2114 | |
2115 <p> | |
2116 Example use: | |
2117 | |
2118 <p><tt><pre> | |
2119 for i in range(1,10) do | |
2120 Io.print("count up:",i) | |
2121 end | |
2122 for i in range(10,0,-1) do | |
2123 Io.print("count down:",i) | |
2124 end | |
2125 </pre></tt></p> | |
2126 | |
2127 <p> | |
2128 Could be defined as: | |
2129 | |
2130 <p><tt><pre> | |
2131 function Luan.range(start, stop, step) | |
2132 step = step or 1 | |
478 | 2133 step == 0 and <a href="#Luan.error">Luan.error</a> "bad argument #3 (step may not be zero)" |
476 | 2134 local i = start |
2135 return function() | |
2136 if step > 0 and i <= stop or step < 0 and i >= stop then | |
2137 local rtn = i | |
2138 i = i + step | |
2139 return rtn | |
2140 end | |
2141 end | |
2142 end | |
2143 </pre></tt></p> | |
2144 | |
2145 | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2146 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2147 <h4 <%=heading_options%> ><a name="Luan.raw_equal"><tt>Luan.raw_equal (v1, v2)</tt></a></h4> |
475 | 2148 |
2149 <p> | |
2150 Checks whether <tt>v1</tt> is equal to <tt>v2</tt>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2151 without invoking any metamethod. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2152 Returns a boolean. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2153 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2154 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2155 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2156 <h4 <%=heading_options%> ><a name="Luan.raw_get"><tt>Luan.raw_get (table, index)</tt></a></h4> |
475 | 2157 |
2158 <p> | |
2159 Gets the real value of <tt>table[index]</tt>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2160 without invoking any metamethod. |
475 | 2161 <tt>table</tt> must be a table; |
2162 <tt>index</tt> may be any value. | |
2163 | |
2164 | |
2165 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2166 <h4 <%=heading_options%> ><a name="Luan.raw_len"><tt>Luan.raw_len (v)</tt></a></h4> |
475 | 2167 |
2168 <p> | |
2169 Returns the length of the object <tt>v</tt>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2170 which must be a table or a string, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2171 without invoking any metamethod. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2172 Returns an integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2173 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2174 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2175 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2176 <h4 <%=heading_options%> ><a name="Luan.raw_set"><tt>Luan.raw_set (table, index, value)</tt></a></h4> |
475 | 2177 |
2178 <p> | |
2179 Sets the real value of <tt>table[index]</tt> to <tt>value</tt>, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2180 without invoking any metamethod. |
475 | 2181 <tt>table</tt> must be a table, |
2182 <tt>index</tt> any value different from <b>nil</b>, | |
2183 and <tt>value</tt> any Lua value. | |
2184 | |
2185 <p> | |
2186 This function returns <tt>table</tt>. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2187 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2188 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2189 <h4 <%=heading_options%> ><a name="Luan.set_metatable"><tt>Luan.set_metatable (table, metatable)</tt></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2190 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2191 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2192 Sets the metatable for the given table. |
475 | 2193 If <tt>metatable</tt> is <b>nil</b>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2194 removes the metatable of the given table. |
475 | 2195 If the original metatable has a <tt>"__metatable"</tt> field, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2196 raises an error. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2197 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2198 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2199 <p> |
475 | 2200 This function returns <tt>table</tt>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2201 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2202 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2203 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2204 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2205 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2206 <hr><h3><a name="pdf-tonumber"><code>tonumber (e [, base])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2207 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2208 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2209 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2210 When called with no <code>base</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2211 <code>tonumber</code> tries to convert its argument to a number. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2212 If the argument is already a number or |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2213 a string convertible to a number, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2214 then <code>tonumber</code> returns this number; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2215 otherwise, it returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2216 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2217 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2218 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2219 The conversion of strings can result in integers or floats, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2220 according to the lexical conventions of Lua (see <a href="#3.1">§3.1</a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2221 (The string may have leading and trailing spaces and a sign.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2222 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2223 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2224 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2225 When called with <code>base</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2226 then <code>e</code> must be a string to be interpreted as |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2227 an integer numeral in that base. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2228 The base may be any integer between 2 and 36, inclusive. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2229 In bases above 10, the letter '<code>A</code>' (in either upper or lower case) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2230 represents 10, '<code>B</code>' represents 11, and so forth, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2231 with '<code>Z</code>' representing 35. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2232 If the string <code>e</code> is not a valid numeral in the given base, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2233 the function returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2234 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2235 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2236 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2237 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2238 <h4 <%=heading_options%> ><a name="Luan.to_string"><tt>Luan.to_string (v)</tt></a></h4> |
475 | 2239 |
2240 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2241 Receives a value of any type and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2242 converts it to a string in a human-readable format. |
475 | 2243 |
2244 <p> | |
2245 If the metatable of <tt>v</tt> has a <tt>"__to_string"</tt> field, | |
2246 then <tt>to_string</tt> calls the corresponding value | |
2247 with <tt>v</tt> as argument, | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2248 and uses the result of the call as its result. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2249 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2250 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2251 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2252 <h4 <%=heading_options%> ><a name="Luan.try"><tt>Luan.try (t)</tt></a></h4> |
476 | 2253 |
2254 <p> | |
2255 Implements try-catch as found in other languages where each block is in table <tt>t</tt>. | |
2256 | |
2257 <p> | |
2258 Example use: | |
2259 | |
2260 <p><tt><pre> | |
2261 try { | |
2262 function() | |
2263 a_dangerous_fn() | |
2264 end; | |
2265 catch = function(e) | |
2266 -- handle error | |
2267 end; | |
2268 finally = function() | |
2269 -- clean up | |
2270 end; | |
2271 } | |
2272 </pre></tt></p> | |
2273 | |
482 | 2274 <p> |
2275 Could be defined as: | |
2276 | |
2277 <p><tt><pre> | |
2278 function Luan.try(t) | |
2279 local r = { <a href="#Luan.pcall">Luan.pcall</a>(t[1]) } | |
2280 if r[1] then | |
2281 Table.remove(r,1) | |
2282 elseif t.catch ~= nil then | |
2283 r = { t.catch(r[2]) } | |
2284 else | |
2285 t.finally and t.finally() | |
2286 r[2].throw() | |
2287 end | |
2288 t.finally and t.finally() | |
2289 return Table.unpack(r) | |
2290 end | |
2291 </pre></tt></p> | |
476 | 2292 |
2293 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2294 <h4 <%=heading_options%> ><a name="Luan.type"><tt>Luan.type (v)</tt></a></h4> |
475 | 2295 |
2296 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2297 Returns the type of its only argument, coded as a string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2298 The possible results of this function are |
475 | 2299 "<tt>nil</tt>" (a string, not the value <b>nil</b>), |
2300 "<tt>number</tt>", | |
2301 "<tt>string</tt>", | |
2302 "<tt>binary</tt>", | |
2303 "<tt>boolean</tt>", | |
2304 "<tt>table</tt>", | |
2305 "<tt>function</tt>", | |
2306 and "<tt>userdata</tt>". | |
2307 | |
2308 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2309 <h4 <%=heading_options%> ><a name="Luan.values"><tt>Luan.values (···)</tt></a></h4> |
476 | 2310 |
2311 <p> | |
2312 Returns a function so that the construction | |
2313 | |
2314 <p><tt><pre> | |
2315 for v in Luan.values(···) do <i>body</i> end | |
2316 </pre></tt></p> | |
2317 | |
2318 <p> | |
2319 will iterate over all values of <tt>···</tt>. | |
2320 | |
2321 | |
475 | 2322 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2323 <h4 <%=heading_options%> ><a name="Luan.VERSION"><tt>Luan.VERSION</tt></a></h4> |
475 | 2324 |
2325 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2326 A global variable (not a function) that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2327 holds a string containing the current interpreter version. |
478 | 2328 The current value of this variable is "<tt><%=Luan.VERSION%></tt>". |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2329 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2330 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2331 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2332 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2333 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2334 |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2335 <h3 <%=heading_options%> ><a name="package_lib">Modules</a></h3> |
476 | 2336 |
2337 <p> | |
2338 Include this library by: | |
2339 | |
2340 <p><tt><pre> | |
2341 local Package = require "luan:Package" | |
2342 </pre></tt></p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2343 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2344 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2345 The package library provides basic |
476 | 2346 facilities for loading modules in Luan. |
2347 | |
2348 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2349 <h4 <%=heading_options%> ><a name="Package.load"><tt>Package.load (mod_uri)</tt></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2350 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2351 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2352 Loads the given module. |
476 | 2353 The function starts by looking into the <a href="#Package.loaded"><tt>Package.loaded</tt></a> table |
2354 to determine whether <tt>mod_uri</tt> is already loaded. | |
2355 If it is, then <tt>Package.load</tt> returns the value stored | |
2356 at <tt>Package.loaded[mod_uri]</tt>. | |
2357 Otherwise, it tries to load a new value for the module. | |
2358 | |
2359 <p> | |
2360 To load a new value, <tt>Package.load</tt> first checks if <tt>mod_uri</tt> starts with "<b>java:</b>". If yes, then this is a Java class which is loaded by special Java code. | |
2361 | |
2362 <p> | |
2363 If <tt>mod_uri</tt> is not a Java class, then <tt>Package.load</tt> tries to read the text of the file referred to by <tt>mod_uri</tt> (using <tt>add_extension</tt>=true). If the file doesn't exist, then <tt>Package.load</tt> returns <b>nil</b>. If the file exists, then its content is compiled into a chunk calling <a href="#Luan.load"><tt>Luan.load</tt></a> and passing in an empty table as the <tt>env</tt> value. This chunk is run passing in <tt>mod_uri</tt> as an argument. If the chunk returns a value other than <b>nil</b>, then that value is the value of this module. Otherwise the <tt>env</tt> that was passed in is the value of this module. | |
2364 | |
2365 <p> | |
2366 If a new value for the module successful loaded, then it is stored in <tt>Package.loaded[mod_uri]</tt>. The value is returned. | |
2367 | |
2368 | |
2369 | |
2370 | |
479
1285c52ea9d4
add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents:
478
diff
changeset
|
2371 <h4 <%=heading_options%> ><a name="Package.loaded"><tt>Package.loaded</tt></a></h4> |
476 | 2372 |
2373 | |
2374 <p> | |
2375 A table used by <a href="#Package.load"><tt>Package.load</tt></a> to control which | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2376 modules are already loaded. |
476 | 2377 When you load a module <tt>mod_uri</tt> and |
2378 <tt>Package.loaded[modname]</tt> is not <b>nil</b>, | |
2379 <a href="#Package.load"><tt>Package.load</tt></a> simply returns the value stored there. | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2380 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2381 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2382 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2383 This variable is only a reference to the real table; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2384 assignments to this variable do not change the |
476 | 2385 table used by <a href="#Package.load"><tt>Package.load</tt></a>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2386 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2387 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2388 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2389 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2390 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2391 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2392 <h2>6.4 – <a name="6.4">String Manipulation</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2393 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2394 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2395 This library provides generic functions for string manipulation, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2396 such as finding and extracting substrings, and pattern matching. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2397 When indexing a string in Lua, the first character is at position 1 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2398 (not at 0, as in C). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2399 Indices are allowed to be negative and are interpreted as indexing backwards, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2400 from the end of the string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2401 Thus, the last character is at position -1, and so on. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2402 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2403 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2404 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2405 The string library provides all its functions inside the table |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2406 <a name="pdf-string"><code>string</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2407 It also sets a metatable for strings |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2408 where the <code>__index</code> field points to the <code>string</code> table. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2409 Therefore, you can use the string functions in object-oriented style. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2410 For instance, <code>string.byte(s,i)</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2411 can be written as <code>s:byte(i)</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2412 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2413 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2414 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2415 The string library assumes one-byte character encodings. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2416 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2417 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2418 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2419 <hr><h3><a name="pdf-string.byte"><code>string.byte (s [, i [, j]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2420 Returns the internal numerical codes of the characters <code>s[i]</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2421 <code>s[i+1]</code>, ..., <code>s[j]</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2422 The default value for <code>i</code> is 1; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2423 the default value for <code>j</code> is <code>i</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2424 These indices are corrected |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2425 following the same rules of function <a href="#pdf-string.sub"><code>string.sub</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2426 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2427 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2428 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2429 Numerical codes are not necessarily portable across platforms. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2430 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2431 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2432 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2433 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2434 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2435 <hr><h3><a name="pdf-string.char"><code>string.char (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2436 Receives zero or more integers. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2437 Returns a string with length equal to the number of arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2438 in which each character has the internal numerical code equal |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2439 to its corresponding argument. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2440 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2441 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2442 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2443 Numerical codes are not necessarily portable across platforms. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2444 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2445 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2446 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2447 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2448 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2449 <hr><h3><a name="pdf-string.dump"><code>string.dump (function [, strip])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2450 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2451 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2452 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2453 Returns a string containing a binary representation |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2454 (a <em>binary chunk</em>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2455 of the given function, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2456 so that a later <a href="#pdf-load"><code>load</code></a> on this string returns |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2457 a copy of the function (but with new upvalues). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2458 If <code>strip</code> is a true value, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2459 the binary representation is created without debug information |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2460 about the function |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2461 (local variable names, lines, etc.). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2462 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2463 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2464 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2465 Functions with upvalues have only their number of upvalues saved. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2466 When (re)loaded, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2467 those upvalues receive fresh instances containing <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2468 (You can use the debug library to serialize |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2469 and reload the upvalues of a function |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2470 in a way adequate to your needs.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2471 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2472 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2473 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2474 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2475 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2476 <hr><h3><a name="pdf-string.find"><code>string.find (s, pattern [, init [, plain]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2477 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2478 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2479 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2480 Looks for the first match of |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2481 <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) in the string <code>s</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2482 If it finds a match, then <code>find</code> returns the indices of <code>s</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2483 where this occurrence starts and ends; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2484 otherwise, it returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2485 A third, optional numerical argument <code>init</code> specifies |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2486 where to start the search; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2487 its default value is 1 and can be negative. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2488 A value of <b>true</b> as a fourth, optional argument <code>plain</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2489 turns off the pattern matching facilities, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2490 so the function does a plain "find substring" operation, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2491 with no characters in <code>pattern</code> being considered magic. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2492 Note that if <code>plain</code> is given, then <code>init</code> must be given as well. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2493 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2494 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2495 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2496 If the pattern has captures, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2497 then in a successful match |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2498 the captured values are also returned, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2499 after the two indices. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2500 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2501 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2502 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2503 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2504 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2505 <hr><h3><a name="pdf-string.format"><code>string.format (formatstring, ···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2506 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2507 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2508 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2509 Returns a formatted version of its variable number of arguments |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2510 following the description given in its first argument (which must be a string). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2511 The format string follows the same rules as the ISO C function <code>sprintf</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2512 The only differences are that the options/modifiers |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2513 <code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, <code>n</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2514 and <code>p</code> are not supported |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2515 and that there is an extra option, <code>q</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2516 The <code>q</code> option formats a string between double quotes, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2517 using escape sequences when necessary to ensure that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2518 it can safely be read back by the Lua interpreter. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2519 For instance, the call |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2520 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2521 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2522 string.format('%q', 'a string with "quotes" and \n new line') |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2523 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2524 may produce the string: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2525 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2526 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2527 "a string with \"quotes\" and \ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2528 new line" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2529 </pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2530 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2531 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2532 Options |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2533 <code>A</code> and <code>a</code> (when available), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2534 <code>E</code>, <code>e</code>, <code>f</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2535 <code>G</code>, and <code>g</code> all expect a number as argument. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2536 Options <code>c</code>, <code>d</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2537 <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2538 expect an integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2539 Option <code>q</code> expects a string; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2540 option <code>s</code> expects a string without embedded zeros. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2541 If the argument to option <code>s</code> is not a string, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2542 it is converted to one following the same rules of <a href="#pdf-tostring"><code>tostring</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2543 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2544 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2545 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2546 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2547 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2548 <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2549 Returns an iterator function that, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2550 each time it is called, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2551 returns the next captures from <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2552 over the string <code>s</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2553 If <code>pattern</code> specifies no captures, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2554 then the whole match is produced in each call. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2555 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2556 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2557 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2558 As an example, the following loop |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2559 will iterate over all the words from string <code>s</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2560 printing one per line: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2561 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2562 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2563 s = "hello world from Lua" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2564 for w in string.gmatch(s, "%a+") do |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2565 print(w) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2566 end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2567 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2568 The next example collects all pairs <code>key=value</code> from the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2569 given string into a table: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2570 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2571 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2572 t = {} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2573 s = "from=world, to=Lua" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2574 for k, v in string.gmatch(s, "(%w+)=(%w+)") do |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2575 t[k] = v |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2576 end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2577 </pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2578 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2579 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2580 For this function, a caret '<code>^</code>' at the start of a pattern does not |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2581 work as an anchor, as this would prevent the iteration. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2582 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2583 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2584 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2585 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2586 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2587 <hr><h3><a name="pdf-string.gsub"><code>string.gsub (s, pattern, repl [, n])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2588 Returns a copy of <code>s</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2589 in which all (or the first <code>n</code>, if given) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2590 occurrences of the <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) have been |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2591 replaced by a replacement string specified by <code>repl</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2592 which can be a string, a table, or a function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2593 <code>gsub</code> also returns, as its second value, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2594 the total number of matches that occurred. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2595 The name <code>gsub</code> comes from <em>Global SUBstitution</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2596 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2597 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2598 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2599 If <code>repl</code> is a string, then its value is used for replacement. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2600 The character <code>%</code> works as an escape character: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2601 any sequence in <code>repl</code> of the form <code>%<em>d</em></code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2602 with <em>d</em> between 1 and 9, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2603 stands for the value of the <em>d</em>-th captured substring. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2604 The sequence <code>%0</code> stands for the whole match. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2605 The sequence <code>%%</code> stands for a single <code>%</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2606 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2607 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2608 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2609 If <code>repl</code> is a table, then the table is queried for every match, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2610 using the first capture as the key. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2611 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2612 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2613 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2614 If <code>repl</code> is a function, then this function is called every time a |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2615 match occurs, with all captured substrings passed as arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2616 in order. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2617 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2618 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2619 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2620 In any case, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2621 if the pattern specifies no captures, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2622 then it behaves as if the whole pattern was inside a capture. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2623 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2624 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2625 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2626 If the value returned by the table query or by the function call |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2627 is a string or a number, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2628 then it is used as the replacement string; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2629 otherwise, if it is <b>false</b> or <b>nil</b>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2630 then there is no replacement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2631 (that is, the original match is kept in the string). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2632 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2633 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2634 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2635 Here are some examples: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2636 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2637 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2638 x = string.gsub("hello world", "(%w+)", "%1 %1") |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2639 --> x="hello hello world world" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2640 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2641 x = string.gsub("hello world", "%w+", "%0 %0", 1) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2642 --> x="hello hello world" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2643 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2644 x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1") |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2645 --> x="world hello Lua from" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2646 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2647 x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2648 --> x="home = /home/roberto, user = roberto" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2649 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2650 x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2651 return load(s)() |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2652 end) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2653 --> x="4+5 = 9" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2654 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2655 local t = {name="lua", version="5.3"} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2656 x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2657 --> x="lua-5.3.tar.gz" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2658 </pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2659 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2660 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2661 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2662 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2663 <hr><h3><a name="pdf-string.len"><code>string.len (s)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2664 Receives a string and returns its length. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2665 The empty string <code>""</code> has length 0. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2666 Embedded zeros are counted, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2667 so <code>"a\000bc\000"</code> has length 5. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2668 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2669 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2670 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2671 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2672 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2673 <hr><h3><a name="pdf-string.lower"><code>string.lower (s)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2674 Receives a string and returns a copy of this string with all |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2675 uppercase letters changed to lowercase. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2676 All other characters are left unchanged. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2677 The definition of what an uppercase letter is depends on the current locale. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2678 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2679 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2680 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2681 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2682 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2683 <hr><h3><a name="pdf-string.match"><code>string.match (s, pattern [, init])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2684 Looks for the first <em>match</em> of |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2685 <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) in the string <code>s</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2686 If it finds one, then <code>match</code> returns |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2687 the captures from the pattern; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2688 otherwise it returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2689 If <code>pattern</code> specifies no captures, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2690 then the whole match is returned. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2691 A third, optional numerical argument <code>init</code> specifies |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2692 where to start the search; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2693 its default value is 1 and can be negative. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2694 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2695 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2696 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2697 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2698 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2699 <hr><h3><a name="pdf-string.pack"><code>string.pack (fmt, v1, v2, ···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2700 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2701 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2702 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2703 Returns a binary string containing the values <code>v1</code>, <code>v2</code>, etc. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2704 packed (that is, serialized in binary form) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2705 according to the format string <code>fmt</code> (see <a href="#6.4.2">§6.4.2</a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2706 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2707 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2708 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2709 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2710 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2711 <hr><h3><a name="pdf-string.packsize"><code>string.packsize (fmt)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2712 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2713 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2714 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2715 Returns the size of a string resulting from <a href="#pdf-string.pack"><code>string.pack</code></a> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2716 with the given format. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2717 The format string cannot have the variable-length options |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2718 '<code>s</code>' or '<code>z</code>' (see <a href="#6.4.2">§6.4.2</a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2719 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2720 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2721 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2722 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2723 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2724 <hr><h3><a name="pdf-string.rep"><code>string.rep (s, n [, sep])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2725 Returns a string that is the concatenation of <code>n</code> copies of |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2726 the string <code>s</code> separated by the string <code>sep</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2727 The default value for <code>sep</code> is the empty string |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2728 (that is, no separator). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2729 Returns the empty string if <code>n</code> is not positive. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2730 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2731 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2732 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2733 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2734 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2735 <hr><h3><a name="pdf-string.reverse"><code>string.reverse (s)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2736 Returns a string that is the string <code>s</code> reversed. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2737 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2738 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2739 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2740 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2741 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2742 <hr><h3><a name="pdf-string.sub"><code>string.sub (s, i [, j])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2743 Returns the substring of <code>s</code> that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2744 starts at <code>i</code> and continues until <code>j</code>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2745 <code>i</code> and <code>j</code> can be negative. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2746 If <code>j</code> is absent, then it is assumed to be equal to -1 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2747 (which is the same as the string length). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2748 In particular, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2749 the call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2750 with length <code>j</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2751 and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2752 with length <code>i</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2753 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2754 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2755 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2756 If, after the translation of negative indices, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2757 <code>i</code> is less than 1, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2758 it is corrected to 1. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2759 If <code>j</code> is greater than the string length, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2760 it is corrected to that length. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2761 If, after these corrections, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2762 <code>i</code> is greater than <code>j</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2763 the function returns the empty string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2764 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2765 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2766 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2767 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2768 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2769 <hr><h3><a name="pdf-string.unpack"><code>string.unpack (fmt, s [, pos])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2770 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2771 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2772 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2773 Returns the values packed in string <code>s</code> (see <a href="#pdf-string.pack"><code>string.pack</code></a>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2774 according to the format string <code>fmt</code> (see <a href="#6.4.2">§6.4.2</a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2775 An optional <code>pos</code> marks where |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2776 to start reading in <code>s</code> (default is 1). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2777 After the read values, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2778 this function also returns the index of the first unread byte in <code>s</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2779 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2780 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2781 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2782 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2783 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2784 <hr><h3><a name="pdf-string.upper"><code>string.upper (s)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2785 Receives a string and returns a copy of this string with all |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2786 lowercase letters changed to uppercase. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2787 All other characters are left unchanged. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2788 The definition of what a lowercase letter is depends on the current locale. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2789 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2790 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2791 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2792 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2793 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2794 <h3>6.4.1 – <a name="6.4.1">Patterns</a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2795 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2796 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2797 Patterns in Lua are described by regular strings, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2798 which are interpreted as patterns by the pattern-matching functions |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2799 <a href="#pdf-string.find"><code>string.find</code></a>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2800 <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2801 <a href="#pdf-string.gsub"><code>string.gsub</code></a>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2802 and <a href="#pdf-string.match"><code>string.match</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2803 This section describes the syntax and the meaning |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2804 (that is, what they match) of these strings. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2805 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2806 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2807 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2808 <h4>Character Class:</h4><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2809 A <em>character class</em> is used to represent a set of characters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2810 The following combinations are allowed in describing a character class: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2811 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2812 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2813 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2814 <li><b><em>x</em>: </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2815 (where <em>x</em> is not one of the <em>magic characters</em> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2816 <code>^$()%.[]*+-?</code>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2817 represents the character <em>x</em> itself. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2818 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2819 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2820 <li><b><code>.</code>: </b> (a dot) represents all characters.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2821 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2822 <li><b><code>%a</code>: </b> represents all letters.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2823 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2824 <li><b><code>%c</code>: </b> represents all control characters.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2825 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2826 <li><b><code>%d</code>: </b> represents all digits.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2827 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2828 <li><b><code>%g</code>: </b> represents all printable characters except space.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2829 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2830 <li><b><code>%l</code>: </b> represents all lowercase letters.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2831 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2832 <li><b><code>%p</code>: </b> represents all punctuation characters.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2833 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2834 <li><b><code>%s</code>: </b> represents all space characters.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2835 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2836 <li><b><code>%u</code>: </b> represents all uppercase letters.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2837 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2838 <li><b><code>%w</code>: </b> represents all alphanumeric characters.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2839 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2840 <li><b><code>%x</code>: </b> represents all hexadecimal digits.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2841 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2842 <li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2843 represents the character <em>x</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2844 This is the standard way to escape the magic characters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2845 Any non-alphanumeric character |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2846 (including all punctuations, even the non-magical) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2847 can be preceded by a '<code>%</code>' |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2848 when used to represent itself in a pattern. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2849 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2850 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2851 <li><b><code>[<em>set</em>]</code>: </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2852 represents the class which is the union of all |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2853 characters in <em>set</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2854 A range of characters can be specified by |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2855 separating the end characters of the range, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2856 in ascending order, with a '<code>-</code>'. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2857 All classes <code>%</code><em>x</em> described above can also be used as |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2858 components in <em>set</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2859 All other characters in <em>set</em> represent themselves. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2860 For example, <code>[%w_]</code> (or <code>[_%w]</code>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2861 represents all alphanumeric characters plus the underscore, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2862 <code>[0-7]</code> represents the octal digits, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2863 and <code>[0-7%l%-]</code> represents the octal digits plus |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2864 the lowercase letters plus the '<code>-</code>' character. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2865 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2866 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2867 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2868 The interaction between ranges and classes is not defined. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2869 Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2870 have no meaning. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2871 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2872 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2873 <li><b><code>[^<em>set</em>]</code>: </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2874 represents the complement of <em>set</em>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2875 where <em>set</em> is interpreted as above. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2876 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2877 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2878 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2879 For all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2880 the corresponding uppercase letter represents the complement of the class. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2881 For instance, <code>%S</code> represents all non-space characters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2882 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2883 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2884 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2885 The definitions of letter, space, and other character groups |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2886 depend on the current locale. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2887 In particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2888 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2889 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2890 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2891 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2892 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2893 <h4>Pattern Item:</h4><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2894 A <em>pattern item</em> can be |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2895 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2896 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2897 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2898 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2899 a single character class, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2900 which matches any single character in the class; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2901 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2902 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2903 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2904 a single character class followed by '<code>*</code>', |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2905 which matches zero or more repetitions of characters in the class. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2906 These repetition items will always match the longest possible sequence; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2907 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2908 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2909 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2910 a single character class followed by '<code>+</code>', |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2911 which matches one or more repetitions of characters in the class. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2912 These repetition items will always match the longest possible sequence; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2913 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2914 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2915 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2916 a single character class followed by '<code>-</code>', |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2917 which also matches zero or more repetitions of characters in the class. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2918 Unlike '<code>*</code>', |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2919 these repetition items will always match the shortest possible sequence; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2920 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2921 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2922 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2923 a single character class followed by '<code>?</code>', |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2924 which matches zero or one occurrence of a character in the class. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2925 It always matches one occurrence if possible; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2926 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2927 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2928 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2929 <code>%<em>n</em></code>, for <em>n</em> between 1 and 9; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2930 such item matches a substring equal to the <em>n</em>-th captured string |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2931 (see below); |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2932 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2933 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2934 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2935 <code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2936 such item matches strings that start with <em>x</em>, end with <em>y</em>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2937 and where the <em>x</em> and <em>y</em> are <em>balanced</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2938 This means that, if one reads the string from left to right, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2939 counting <em>+1</em> for an <em>x</em> and <em>-1</em> for a <em>y</em>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2940 the ending <em>y</em> is the first <em>y</em> where the count reaches 0. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2941 For instance, the item <code>%b()</code> matches expressions with |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2942 balanced parentheses. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2943 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2944 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2945 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2946 <code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2947 such item matches an empty string at any position such that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2948 the next character belongs to <em>set</em> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2949 and the previous character does not belong to <em>set</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2950 The set <em>set</em> is interpreted as previously described. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2951 The beginning and the end of the subject are handled as if |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2952 they were the character '<code>\0</code>'. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2953 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2954 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2955 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2956 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2957 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2958 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2959 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2960 <h4>Pattern:</h4><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2961 A <em>pattern</em> is a sequence of pattern items. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2962 A caret '<code>^</code>' at the beginning of a pattern anchors the match at the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2963 beginning of the subject string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2964 A '<code>$</code>' at the end of a pattern anchors the match at the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2965 end of the subject string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2966 At other positions, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2967 '<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2968 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2969 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2970 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2971 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2972 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2973 <h4>Captures:</h4><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2974 A pattern can contain sub-patterns enclosed in parentheses; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2975 they describe <em>captures</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2976 When a match succeeds, the substrings of the subject string |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2977 that match captures are stored (<em>captured</em>) for future use. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2978 Captures are numbered according to their left parentheses. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2979 For instance, in the pattern <code>"(a*(.)%w(%s*))"</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2980 the part of the string matching <code>"a*(.)%w(%s*)"</code> is |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2981 stored as the first capture (and therefore has number 1); |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2982 the character matching "<code>.</code>" is captured with number 2, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2983 and the part matching "<code>%s*</code>" has number 3. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2984 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2985 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2986 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2987 As a special case, the empty capture <code>()</code> captures |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2988 the current string position (a number). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2989 For instance, if we apply the pattern <code>"()aa()"</code> on the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2990 string <code>"flaaap"</code>, there will be two captures: 3 and 5. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2991 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2992 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2993 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2994 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2995 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2996 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2997 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2998 <h3>6.4.2 – <a name="6.4.2">Format Strings for Pack and Unpack</a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2999 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3000 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3001 The first argument to <a href="#pdf-string.pack"><code>string.pack</code></a>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3002 <a href="#pdf-string.packsize"><code>string.packsize</code></a>, and <a href="#pdf-string.unpack"><code>string.unpack</code></a> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3003 is a format string, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3004 which describes the layout of the structure being created or read. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3005 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3006 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3007 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3008 A format string is a sequence of conversion options. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3009 The conversion options are as follows: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3010 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3011 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3012 <li><b><code><</code>: </b>sets little endian</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3013 <li><b><code>></code>: </b>sets big endian</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3014 <li><b><code>=</code>: </b>sets native endian</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3015 <li><b><code>![<em>n</em>]</code>: </b>sets maximum alignment to <code>n</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3016 (default is native alignment)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3017 <li><b><code>b</code>: </b>a signed byte (<code>char</code>)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3018 <li><b><code>B</code>: </b>an unsigned byte (<code>char</code>)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3019 <li><b><code>h</code>: </b>a signed <code>short</code> (native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3020 <li><b><code>H</code>: </b>an unsigned <code>short</code> (native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3021 <li><b><code>l</code>: </b>a signed <code>long</code> (native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3022 <li><b><code>L</code>: </b>an unsigned <code>long</code> (native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3023 <li><b><code>j</code>: </b>a <code>lua_Integer</code></li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3024 <li><b><code>J</code>: </b>a <code>lua_Unsigned</code></li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3025 <li><b><code>T</code>: </b>a <code>size_t</code> (native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3026 <li><b><code>i[<em>n</em>]</code>: </b>a signed <code>int</code> with <code>n</code> bytes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3027 (default is native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3028 <li><b><code>I[<em>n</em>]</code>: </b>an unsigned <code>int</code> with <code>n</code> bytes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3029 (default is native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3030 <li><b><code>f</code>: </b>a <code>float</code> (native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3031 <li><b><code>d</code>: </b>a <code>double</code> (native size)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3032 <li><b><code>n</code>: </b>a <code>lua_Number</code></li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3033 <li><b><code>c<em>n</em></code>: </b>a fixed-sized string with <code>n</code> bytes</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3034 <li><b><code>z</code>: </b>a zero-terminated string</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3035 <li><b><code>s[<em>n</em>]</code>: </b>a string preceded by its length |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3036 coded as an unsigned integer with <code>n</code> bytes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3037 (default is a <code>size_t</code>)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3038 <li><b><code>x</code>: </b>one byte of padding</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3039 <li><b><code>X<em>op</em></code>: </b>an empty item that aligns |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3040 according to option <code>op</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3041 (which is otherwise ignored)</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3042 <li><b>'<code> </code>': </b>(empty space) ignored</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3043 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3044 (A "<code>[<em>n</em>]</code>" means an optional integral numeral.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3045 Except for padding, spaces, and configurations |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3046 (options "<code>xX <=>!</code>"), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3047 each option corresponds to an argument (in <a href="#pdf-string.pack"><code>string.pack</code></a>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3048 or a result (in <a href="#pdf-string.unpack"><code>string.unpack</code></a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3049 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3050 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3051 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3052 For options "<code>!<em>n</em></code>", "<code>s<em>n</em></code>", "<code>i<em>n</em></code>", and "<code>I<em>n</em></code>", |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3053 <code>n</code> can be any integer between 1 and 16. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3054 All integral options check overflows; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3055 <a href="#pdf-string.pack"><code>string.pack</code></a> checks whether the given value fits in the given size; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3056 <a href="#pdf-string.unpack"><code>string.unpack</code></a> checks whether the read value fits in a Lua integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3057 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3058 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3059 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3060 Any format string starts as if prefixed by "<code>!1=</code>", |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3061 that is, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3062 with maximum alignment of 1 (no alignment) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3063 and native endianness. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3064 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3065 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3066 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3067 Alignment works as follows: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3068 For each option, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3069 the format gets extra padding until the data starts |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3070 at an offset that is a multiple of the minimum between the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3071 option size and the maximum alignment; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3072 this minimum must be a power of 2. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3073 Options "<code>c</code>" and "<code>z</code>" are not aligned; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3074 option "<code>s</code>" follows the alignment of its starting integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3075 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3076 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3077 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3078 All padding is filled with zeros by <a href="#pdf-string.pack"><code>string.pack</code></a> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3079 (and ignored by <a href="#pdf-string.unpack"><code>string.unpack</code></a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3080 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3081 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3082 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3083 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3084 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3085 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3086 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3087 <h2>6.5 – <a name="6.5">UTF-8 Support</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3088 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3089 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3090 This library provides basic support for UTF-8 encoding. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3091 It provides all its functions inside the table <a name="pdf-utf8"><code>utf8</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3092 This library does not provide any support for Unicode other |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3093 than the handling of the encoding. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3094 Any operation that needs the meaning of a character, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3095 such as character classification, is outside its scope. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3096 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3097 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3098 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3099 Unless stated otherwise, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3100 all functions that expect a byte position as a parameter |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3101 assume that the given position is either the start of a byte sequence |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3102 or one plus the length of the subject string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3103 As in the string library, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3104 negative indices count from the end of the string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3105 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3106 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3107 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3108 <hr><h3><a name="pdf-utf8.char"><code>utf8.char (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3109 Receives zero or more integers, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3110 converts each one to its corresponding UTF-8 byte sequence |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3111 and returns a string with the concatenation of all these sequences. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3112 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3113 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3114 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3115 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3116 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3117 <hr><h3><a name="pdf-utf8.charpattern"><code>utf8.charpattern</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3118 The pattern (a string, not a function) "<code>[\0-\x7F\xC2-\xF4][\x80-\xBF]*</code>" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3119 (see <a href="#6.4.1">§6.4.1</a>), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3120 which matches exactly one UTF-8 byte sequence, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3121 assuming that the subject is a valid UTF-8 string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3122 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3123 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3124 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3125 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3126 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3127 <hr><h3><a name="pdf-utf8.codes"><code>utf8.codes (s)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3128 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3129 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3130 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3131 Returns values so that the construction |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3132 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3133 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3134 for p, c in utf8.codes(s) do <em>body</em> end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3135 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3136 will iterate over all characters in string <code>s</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3137 with <code>p</code> being the position (in bytes) and <code>c</code> the code point |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3138 of each character. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3139 It raises an error if it meets any invalid byte sequence. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3140 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3141 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3142 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3143 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3144 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3145 <hr><h3><a name="pdf-utf8.codepoint"><code>utf8.codepoint (s [, i [, j]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3146 Returns the codepoints (as integers) from all characters in <code>s</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3147 that start between byte position <code>i</code> and <code>j</code> (both included). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3148 The default for <code>i</code> is 1 and for <code>j</code> is <code>i</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3149 It raises an error if it meets any invalid byte sequence. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3150 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3151 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3152 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3153 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3154 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3155 <hr><h3><a name="pdf-utf8.len"><code>utf8.len (s [, i [, j]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3156 Returns the number of UTF-8 characters in string <code>s</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3157 that start between positions <code>i</code> and <code>j</code> (both inclusive). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3158 The default for <code>i</code> is 1 and for <code>j</code> is -1. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3159 If it finds any invalid byte sequence, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3160 returns a false value plus the position of the first invalid byte. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3161 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3162 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3163 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3164 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3165 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3166 <hr><h3><a name="pdf-utf8.offset"><code>utf8.offset (s, n [, i])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3167 Returns the position (in bytes) where the encoding of the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3168 <code>n</code>-th character of <code>s</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3169 (counting from position <code>i</code>) starts. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3170 A negative <code>n</code> gets characters before position <code>i</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3171 The default for <code>i</code> is 1 when <code>n</code> is non-negative |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3172 and <code>#s + 1</code> otherwise, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3173 so that <code>utf8.offset(s, -n)</code> gets the offset of the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3174 <code>n</code>-th character from the end of the string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3175 If the specified character is neither in the subject |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3176 nor right after its end, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3177 the function returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3178 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3179 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3180 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3181 As a special case, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3182 when <code>n</code> is 0 the function returns the start of the encoding |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3183 of the character that contains the <code>i</code>-th byte of <code>s</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3184 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3185 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3186 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3187 This function assumes that <code>s</code> is a valid UTF-8 string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3188 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3189 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3190 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3191 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3192 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3193 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3194 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3195 <h2>6.6 – <a name="6.6">Table Manipulation</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3196 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3197 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3198 This library provides generic functions for table manipulation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3199 It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3200 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3201 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3202 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3203 Remember that, whenever an operation needs the length of a table, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3204 the table must be a proper sequence |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3205 or have a <code>__len</code> metamethod (see <a href="#3.4.7">§3.4.7</a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3206 All functions ignore non-numeric keys |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3207 in the tables given as arguments. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3208 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3209 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3210 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3211 <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3212 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3213 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3214 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3215 Given a list where all elements are strings or numbers, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3216 returns the string <code>list[i]..sep..list[i+1] ··· sep..list[j]</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3217 The default value for <code>sep</code> is the empty string, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3218 the default for <code>i</code> is 1, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3219 and the default for <code>j</code> is <code>#list</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3220 If <code>i</code> is greater than <code>j</code>, returns the empty string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3221 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3222 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3223 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3224 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3225 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3226 <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3227 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3228 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3229 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3230 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3231 shifting up the elements |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3232 <code>list[pos], list[pos+1], ···, list[#list]</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3233 The default value for <code>pos</code> is <code>#list+1</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3234 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3235 of list <code>t</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3236 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3237 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3238 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3239 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3240 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3241 <hr><h3><a name="pdf-table.move"><code>table.move (a1, f, e, t [,a2])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3242 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3243 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3244 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3245 Moves elements from table <code>a1</code> to table <code>a2</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3246 This function performs the equivalent to the following |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3247 multiple assignment: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3248 <code>a2[t],··· = a1[f],···,a1[e]</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3249 The default for <code>a2</code> is <code>a1</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3250 The destination range can overlap with the source range. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3251 Index <code>f</code> must be positive. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3252 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3253 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3254 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3255 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3256 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3257 <hr><h3><a name="pdf-table.pack"><code>table.pack (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3258 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3259 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3260 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3261 Returns a new table with all parameters stored into keys 1, 2, etc. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3262 and with a field "<code>n</code>" with the total number of parameters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3263 Note that the resulting table may not be a sequence. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3264 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3265 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3266 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3267 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3268 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3269 <hr><h3><a name="pdf-table.remove"><code>table.remove (list [, pos])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3270 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3271 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3272 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3273 Removes from <code>list</code> the element at position <code>pos</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3274 returning the value of the removed element. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3275 When <code>pos</code> is an integer between 1 and <code>#list</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3276 it shifts down the elements |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3277 <code>list[pos+1], list[pos+2], ···, list[#list]</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3278 and erases element <code>list[#list]</code>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3279 The index <code>pos</code> can also be 0 when <code>#list</code> is 0, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3280 or <code>#list + 1</code>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3281 in those cases, the function erases the element <code>list[pos]</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3282 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3283 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3284 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3285 The default value for <code>pos</code> is <code>#list</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3286 so that a call <code>table.remove(l)</code> removes the last element |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3287 of list <code>l</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3288 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3289 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3290 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3291 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3292 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3293 <hr><h3><a name="pdf-table.sort"><code>table.sort (list [, comp])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3294 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3295 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3296 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3297 Sorts list elements in a given order, <em>in-place</em>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3298 from <code>list[1]</code> to <code>list[#list]</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3299 If <code>comp</code> is given, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3300 then it must be a function that receives two list elements |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3301 and returns true when the first element must come |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3302 before the second in the final order |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3303 (so that <code>not comp(list[i+1],list[i])</code> will be true after the sort). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3304 If <code>comp</code> is not given, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3305 then the standard Lua operator <code><</code> is used instead. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3306 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3307 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3308 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3309 The sort algorithm is not stable; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3310 that is, elements considered equal by the given order |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3311 may have their relative positions changed by the sort. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3312 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3313 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3314 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3315 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3316 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3317 <hr><h3><a name="pdf-table.unpack"><code>table.unpack (list [, i [, j]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3318 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3319 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3320 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3321 Returns the elements from the given list. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3322 This function is equivalent to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3323 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3324 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3325 return list[i], list[i+1], ···, list[j] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3326 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3327 By default, <code>i</code> is 1 and <code>j</code> is <code>#list</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3328 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3329 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3330 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3331 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3332 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3333 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3334 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3335 <h2>6.7 – <a name="6.7">Mathematical Functions</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3336 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3337 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3338 This library provides basic mathematical functions. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3339 It provides all its functions and constants inside the table <a name="pdf-math"><code>math</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3340 Functions with the annotation "<code>integer/float</code>" give |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3341 integer results for integer arguments |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3342 and float results for float (or mixed) arguments. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3343 Rounding functions |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3344 (<a href="#pdf-math.ceil"><code>math.ceil</code></a>, <a href="#pdf-math.floor"><code>math.floor</code></a>, and <a href="#pdf-math.modf"><code>math.modf</code></a>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3345 return an integer when the result fits in the range of an integer, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3346 or a float otherwise. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3347 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3348 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3349 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3350 <hr><h3><a name="pdf-math.abs"><code>math.abs (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3351 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3352 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3353 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3354 Returns the absolute value of <code>x</code>. (integer/float) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3355 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3356 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3357 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3358 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3359 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3360 <hr><h3><a name="pdf-math.acos"><code>math.acos (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3361 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3362 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3363 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3364 Returns the arc cosine of <code>x</code> (in radians). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3365 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3366 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3367 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3368 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3369 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3370 <hr><h3><a name="pdf-math.asin"><code>math.asin (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3371 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3372 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3373 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3374 Returns the arc sine of <code>x</code> (in radians). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3375 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3376 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3377 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3378 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3379 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3380 <hr><h3><a name="pdf-math.atan"><code>math.atan (y [, x])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3381 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3382 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3383 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3384 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3385 Returns the arc tangent of <code>y/x</code> (in radians), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3386 but uses the signs of both parameters to find the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3387 quadrant of the result. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3388 (It also handles correctly the case of <code>x</code> being zero.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3389 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3390 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3391 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3392 The default value for <code>x</code> is 1, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3393 so that the call <code>math.atan(y)</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3394 returns the arc tangent of <code>y</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3395 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3396 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3397 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3398 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3399 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3400 <hr><h3><a name="pdf-math.ceil"><code>math.ceil (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3401 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3402 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3403 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3404 Returns the smallest integral value larger than or equal to <code>x</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3405 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3406 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3407 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3408 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3409 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3410 <hr><h3><a name="pdf-math.cos"><code>math.cos (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3411 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3412 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3413 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3414 Returns the cosine of <code>x</code> (assumed to be in radians). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3415 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3416 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3417 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3418 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3419 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3420 <hr><h3><a name="pdf-math.deg"><code>math.deg (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3421 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3422 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3423 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3424 Converts the angle <code>x</code> from radians to degrees. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3425 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3426 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3427 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3428 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3429 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3430 <hr><h3><a name="pdf-math.exp"><code>math.exp (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3431 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3432 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3433 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3434 Returns the value <em>e<sup>x</sup></em> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3435 (where <code>e</code> is the base of natural logarithms). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3436 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3437 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3438 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3439 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3440 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3441 <hr><h3><a name="pdf-math.floor"><code>math.floor (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3442 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3443 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3444 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3445 Returns the largest integral value smaller than or equal to <code>x</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3446 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3447 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3448 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3449 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3450 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3451 <hr><h3><a name="pdf-math.fmod"><code>math.fmod (x, y)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3452 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3453 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3454 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3455 Returns the remainder of the division of <code>x</code> by <code>y</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3456 that rounds the quotient towards zero. (integer/float) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3457 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3458 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3459 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3460 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3461 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3462 <hr><h3><a name="pdf-math.huge"><code>math.huge</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3463 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3464 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3465 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3466 The float value <code>HUGE_VAL</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3467 a value larger than any other numerical value. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3468 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3469 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3470 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3471 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3472 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3473 <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3474 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3475 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3476 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3477 Returns the logarithm of <code>x</code> in the given base. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3478 The default for <code>base</code> is <em>e</em> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3479 (so that the function returns the natural logarithm of <code>x</code>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3480 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3481 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3482 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3483 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3484 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3485 <hr><h3><a name="pdf-math.max"><code>math.max (x, ···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3486 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3487 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3488 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3489 Returns the argument with the maximum value, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3490 according to the Lua operator <code><</code>. (integer/float) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3491 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3492 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3493 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3494 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3495 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3496 <hr><h3><a name="pdf-math.maxinteger"><code>math.maxinteger</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3497 An integer with the maximum value for an integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3498 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3499 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3500 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3501 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3502 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3503 <hr><h3><a name="pdf-math.min"><code>math.min (x, ···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3504 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3505 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3506 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3507 Returns the argument with the minimum value, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3508 according to the Lua operator <code><</code>. (integer/float) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3509 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3510 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3511 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3512 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3513 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3514 <hr><h3><a name="pdf-math.mininteger"><code>math.mininteger</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3515 An integer with the minimum value for an integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3516 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3517 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3518 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3519 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3520 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3521 <hr><h3><a name="pdf-math.modf"><code>math.modf (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3522 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3523 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3524 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3525 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3526 Its second result is always a float. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3527 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3528 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3529 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3530 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3531 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3532 <hr><h3><a name="pdf-math.pi"><code>math.pi</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3533 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3534 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3535 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3536 The value of <em>π</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3537 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3538 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3539 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3540 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3541 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3542 <hr><h3><a name="pdf-math.rad"><code>math.rad (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3543 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3544 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3545 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3546 Converts the angle <code>x</code> from degrees to radians. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3547 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3548 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3549 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3550 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3551 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3552 <hr><h3><a name="pdf-math.random"><code>math.random ([m [, n]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3553 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3554 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3555 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3556 When called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3557 returns a pseudo-random float with uniform distribution |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3558 in the range <em>[0,1)</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3559 When called with two integers <code>m</code> and <code>n</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3560 <code>math.random</code> returns a pseudo-random integer |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3561 with uniform distribution in the range <em>[m, n]</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3562 (The value <em>m-n</em> cannot be negative and must fit in a Lua integer.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3563 The call <code>math.random(n)</code> is equivalent to <code>math.random(1,n)</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3564 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3565 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3566 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3567 This function is an interface to the underling |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3568 pseudo-random generator function provided by C. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3569 No guarantees can be given for its statistical properties. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3570 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3571 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3572 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3573 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3574 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3575 <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3576 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3577 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3578 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3579 Sets <code>x</code> as the "seed" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3580 for the pseudo-random generator: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3581 equal seeds produce equal sequences of numbers. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3582 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3583 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3584 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3585 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3586 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3587 <hr><h3><a name="pdf-math.sin"><code>math.sin (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3588 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3589 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3590 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3591 Returns the sine of <code>x</code> (assumed to be in radians). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3592 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3593 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3594 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3595 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3596 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3597 <hr><h3><a name="pdf-math.sqrt"><code>math.sqrt (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3598 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3599 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3600 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3601 Returns the square root of <code>x</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3602 (You can also use the expression <code>x^0.5</code> to compute this value.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3603 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3604 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3605 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3606 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3607 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3608 <hr><h3><a name="pdf-math.tan"><code>math.tan (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3609 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3610 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3611 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3612 Returns the tangent of <code>x</code> (assumed to be in radians). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3613 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3614 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3615 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3616 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3617 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3618 <hr><h3><a name="pdf-math.tointeger"><code>math.tointeger (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3619 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3620 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3621 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3622 If the value <code>x</code> is convertible to an integer, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3623 returns that integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3624 Otherwise, returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3625 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3626 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3627 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3628 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3629 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3630 <hr><h3><a name="pdf-math.type"><code>math.type (x)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3631 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3632 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3633 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3634 Returns "<code>integer</code>" if <code>x</code> is an integer, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3635 "<code>float</code>" if it is a float, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3636 or <b>nil</b> if <code>x</code> is not a number. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3637 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3638 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3639 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3640 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3641 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3642 <hr><h3><a name="pdf-math.ult"><code>math.ult (m, n)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3643 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3644 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3645 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3646 Returns a boolean, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3647 true if integer <code>m</code> is below integer <code>n</code> when |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3648 they are compared as unsigned integers. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3649 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3650 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3651 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3652 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3653 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3654 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3655 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3656 <h2>6.8 – <a name="6.8">Input and Output Facilities</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3657 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3658 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3659 The I/O library provides two different styles for file manipulation. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3660 The first one uses implicit file handles; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3661 that is, there are operations to set a default input file and a |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3662 default output file, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3663 and all input/output operations are over these default files. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3664 The second style uses explicit file handles. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3665 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3666 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3667 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3668 When using implicit file handles, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3669 all operations are supplied by table <a name="pdf-io"><code>io</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3670 When using explicit file handles, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3671 the operation <a href="#pdf-io.open"><code>io.open</code></a> returns a file handle |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3672 and then all operations are supplied as methods of the file handle. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3673 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3674 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3675 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3676 The table <code>io</code> also provides |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3677 three predefined file handles with their usual meanings from C: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3678 <a name="pdf-io.stdin"><code>io.stdin</code></a>, <a name="pdf-io.stdout"><code>io.stdout</code></a>, and <a name="pdf-io.stderr"><code>io.stderr</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3679 The I/O library never closes these files. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3680 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3681 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3682 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3683 Unless otherwise stated, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3684 all I/O functions return <b>nil</b> on failure |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3685 (plus an error message as a second result and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3686 a system-dependent error code as a third result) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3687 and some value different from <b>nil</b> on success. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3688 On non-POSIX systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3689 the computation of the error message and error code |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3690 in case of errors |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3691 may be not thread safe, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3692 because they rely on the global C variable <code>errno</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3693 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3694 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3695 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3696 <hr><h3><a name="pdf-io.close"><code>io.close ([file])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3697 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3698 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3699 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3700 Equivalent to <code>file:close()</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3701 Without a <code>file</code>, closes the default output file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3702 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3703 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3704 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3705 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3706 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3707 <hr><h3><a name="pdf-io.flush"><code>io.flush ()</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3708 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3709 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3710 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3711 Equivalent to <code>io.output():flush()</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3712 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3713 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3714 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3715 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3716 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3717 <hr><h3><a name="pdf-io.input"><code>io.input ([file])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3718 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3719 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3720 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3721 When called with a file name, it opens the named file (in text mode), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3722 and sets its handle as the default input file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3723 When called with a file handle, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3724 it simply sets this file handle as the default input file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3725 When called without parameters, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3726 it returns the current default input file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3727 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3728 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3729 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3730 In case of errors this function raises the error, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3731 instead of returning an error code. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3732 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3733 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3734 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3735 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3736 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3737 <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename ···])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3738 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3739 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3740 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3741 Opens the given file name in read mode |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3742 and returns an iterator function that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3743 works like <code>file:lines(···)</code> over the opened file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3744 When the iterator function detects the end of file, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3745 it returns no values (to finish the loop) and automatically closes the file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3746 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3747 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3748 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3749 The call <code>io.lines()</code> (with no file name) is equivalent |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3750 to <code>io.input():lines("*l")</code>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3751 that is, it iterates over the lines of the default input file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3752 In this case it does not close the file when the loop ends. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3753 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3754 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3755 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3756 In case of errors this function raises the error, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3757 instead of returning an error code. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3758 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3759 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3760 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3761 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3762 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3763 <hr><h3><a name="pdf-io.open"><code>io.open (filename [, mode])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3764 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3765 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3766 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3767 This function opens a file, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3768 in the mode specified in the string <code>mode</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3769 It returns a new file handle, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3770 or, in case of errors, <b>nil</b> plus an error message. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3771 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3772 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3773 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3774 The <code>mode</code> string can be any of the following: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3775 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3776 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3777 <li><b>"<code>r</code>": </b> read mode (the default);</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3778 <li><b>"<code>w</code>": </b> write mode;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3779 <li><b>"<code>a</code>": </b> append mode;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3780 <li><b>"<code>r+</code>": </b> update mode, all previous data is preserved;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3781 <li><b>"<code>w+</code>": </b> update mode, all previous data is erased;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3782 <li><b>"<code>a+</code>": </b> append update mode, previous data is preserved, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3783 writing is only allowed at the end of file.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3784 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3785 The <code>mode</code> string can also have a '<code>b</code>' at the end, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3786 which is needed in some systems to open the file in binary mode. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3787 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3788 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3789 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3790 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3791 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3792 <hr><h3><a name="pdf-io.output"><code>io.output ([file])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3793 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3794 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3795 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3796 Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3797 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3798 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3799 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3800 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3801 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3802 <hr><h3><a name="pdf-io.popen"><code>io.popen (prog [, mode])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3803 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3804 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3805 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3806 This function is system dependent and is not available |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3807 on all platforms. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3808 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3809 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3810 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3811 Starts program <code>prog</code> in a separated process and returns |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3812 a file handle that you can use to read data from this program |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3813 (if <code>mode</code> is <code>"r"</code>, the default) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3814 or to write data to this program |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3815 (if <code>mode</code> is <code>"w"</code>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3816 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3817 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3818 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3819 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3820 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3821 <hr><h3><a name="pdf-io.read"><code>io.read (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3822 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3823 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3824 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3825 Equivalent to <code>io.input():read(···)</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3826 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3827 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3828 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3829 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3830 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3831 <hr><h3><a name="pdf-io.tmpfile"><code>io.tmpfile ()</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3832 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3833 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3834 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3835 Returns a handle for a temporary file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3836 This file is opened in update mode |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3837 and it is automatically removed when the program ends. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3838 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3839 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3840 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3841 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3842 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3843 <hr><h3><a name="pdf-io.type"><code>io.type (obj)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3844 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3845 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3846 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3847 Checks whether <code>obj</code> is a valid file handle. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3848 Returns the string <code>"file"</code> if <code>obj</code> is an open file handle, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3849 <code>"closed file"</code> if <code>obj</code> is a closed file handle, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3850 or <b>nil</b> if <code>obj</code> is not a file handle. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3851 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3852 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3853 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3854 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3855 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3856 <hr><h3><a name="pdf-io.write"><code>io.write (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3857 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3858 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3859 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3860 Equivalent to <code>io.output():write(···)</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3861 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3862 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3863 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3864 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3865 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3866 <hr><h3><a name="pdf-file:close"><code>file:close ()</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3867 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3868 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3869 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3870 Closes <code>file</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3871 Note that files are automatically closed when |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3872 their handles are garbage collected, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3873 but that takes an unpredictable amount of time to happen. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3874 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3875 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3876 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3877 When closing a file handle created with <a href="#pdf-io.popen"><code>io.popen</code></a>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3878 <a href="#pdf-file:close"><code>file:close</code></a> returns the same values |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3879 returned by <a href="#pdf-os.execute"><code>os.execute</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3880 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3881 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3882 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3883 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3884 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3885 <hr><h3><a name="pdf-file:flush"><code>file:flush ()</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3886 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3887 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3888 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3889 Saves any written data to <code>file</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3890 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3891 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3892 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3893 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3894 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3895 <hr><h3><a name="pdf-file:lines"><code>file:lines (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3896 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3897 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3898 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3899 Returns an iterator function that, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3900 each time it is called, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3901 reads the file according to the given formats. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3902 When no format is given, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3903 uses "<code>l</code>" as a default. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3904 As an example, the construction |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3905 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3906 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3907 for c in file:lines(1) do <em>body</em> end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3908 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3909 will iterate over all characters of the file, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3910 starting at the current position. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3911 Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3912 when the loop ends. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3913 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3914 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3915 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3916 In case of errors this function raises the error, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3917 instead of returning an error code. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3918 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3919 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3920 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3921 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3922 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3923 <hr><h3><a name="pdf-file:read"><code>file:read (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3924 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3925 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3926 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3927 Reads the file <code>file</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3928 according to the given formats, which specify what to read. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3929 For each format, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3930 the function returns a string or a number with the characters read, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3931 or <b>nil</b> if it cannot read data with the specified format. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3932 (In this latter case, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3933 the function does not read subsequent formats.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3934 When called without formats, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3935 it uses a default format that reads the next line |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3936 (see below). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3937 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3938 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3939 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3940 The available formats are |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3941 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3942 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3943 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3944 <li><b>"<code>n</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3945 reads a numeral and returns it as a float or an integer, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3946 following the lexical conventions of Lua. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3947 (The numeral may have leading spaces and a sign.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3948 This format always reads the longest input sequence that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3949 is a valid prefix for a number; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3950 if that prefix does not form a valid number |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3951 (e.g., an empty string, "<code>0x</code>", or "<code>3.4e-</code>"), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3952 it is discarded and the function returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3953 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3954 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3955 <li><b>"<code>i</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3956 reads an integral number and returns it as an integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3957 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3958 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3959 <li><b>"<code>a</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3960 reads the whole file, starting at the current position. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3961 On end of file, it returns the empty string. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3962 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3963 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3964 <li><b>"<code>l</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3965 reads the next line skipping the end of line, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3966 returning <b>nil</b> on end of file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3967 This is the default format. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3968 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3969 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3970 <li><b>"<code>L</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3971 reads the next line keeping the end-of-line character (if present), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3972 returning <b>nil</b> on end of file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3973 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3974 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3975 <li><b><em>number</em>: </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3976 reads a string with up to this number of bytes, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3977 returning <b>nil</b> on end of file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3978 If <code>number</code> is zero, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3979 it reads nothing and returns an empty string, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3980 or <b>nil</b> on end of file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3981 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3982 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3983 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3984 The formats "<code>l</code>" and "<code>L</code>" should be used only for text files. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3985 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3986 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3987 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3988 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3989 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3990 <hr><h3><a name="pdf-file:seek"><code>file:seek ([whence [, offset]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3991 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3992 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3993 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3994 Sets and gets the file position, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3995 measured from the beginning of the file, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3996 to the position given by <code>offset</code> plus a base |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3997 specified by the string <code>whence</code>, as follows: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3998 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3999 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4000 <li><b>"<code>set</code>": </b> base is position 0 (beginning of the file);</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4001 <li><b>"<code>cur</code>": </b> base is current position;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4002 <li><b>"<code>end</code>": </b> base is end of file;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4003 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4004 In case of success, <code>seek</code> returns the final file position, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4005 measured in bytes from the beginning of the file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4006 If <code>seek</code> fails, it returns <b>nil</b>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4007 plus a string describing the error. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4008 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4009 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4010 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4011 The default value for <code>whence</code> is <code>"cur"</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4012 and for <code>offset</code> is 0. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4013 Therefore, the call <code>file:seek()</code> returns the current |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4014 file position, without changing it; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4015 the call <code>file:seek("set")</code> sets the position to the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4016 beginning of the file (and returns 0); |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4017 and the call <code>file:seek("end")</code> sets the position to the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4018 end of the file, and returns its size. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4019 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4020 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4021 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4022 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4023 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4024 <hr><h3><a name="pdf-file:setvbuf"><code>file:setvbuf (mode [, size])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4025 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4026 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4027 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4028 Sets the buffering mode for an output file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4029 There are three available modes: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4030 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4031 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4032 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4033 <li><b>"<code>no</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4034 no buffering; the result of any output operation appears immediately. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4035 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4036 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4037 <li><b>"<code>full</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4038 full buffering; output operation is performed only |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4039 when the buffer is full or when |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4040 you explicitly <code>flush</code> the file (see <a href="#pdf-io.flush"><code>io.flush</code></a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4041 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4042 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4043 <li><b>"<code>line</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4044 line buffering; output is buffered until a newline is output |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4045 or there is any input from some special files |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4046 (such as a terminal device). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4047 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4048 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4049 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4050 For the last two cases, <code>size</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4051 specifies the size of the buffer, in bytes. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4052 The default is an appropriate size. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4053 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4054 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4055 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4056 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4057 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4058 <hr><h3><a name="pdf-file:write"><code>file:write (···)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4059 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4060 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4061 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4062 Writes the value of each of its arguments to <code>file</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4063 The arguments must be strings or numbers. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4064 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4065 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4066 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4067 In case of success, this function returns <code>file</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4068 Otherwise it returns <b>nil</b> plus a string describing the error. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4069 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4070 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4071 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4072 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4073 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4074 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4075 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4076 <h2>6.9 – <a name="6.9">Operating System Facilities</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4077 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4078 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4079 This library is implemented through table <a name="pdf-os"><code>os</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4080 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4081 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4082 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4083 <hr><h3><a name="pdf-os.clock"><code>os.clock ()</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4084 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4085 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4086 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4087 Returns an approximation of the amount in seconds of CPU time |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4088 used by the program. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4089 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4090 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4091 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4092 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4093 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4094 <hr><h3><a name="pdf-os.date"><code>os.date ([format [, time]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4095 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4096 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4097 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4098 Returns a string or a table containing date and time, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4099 formatted according to the given string <code>format</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4100 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4101 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4102 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4103 If the <code>time</code> argument is present, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4104 this is the time to be formatted |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4105 (see the <a href="#pdf-os.time"><code>os.time</code></a> function for a description of this value). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4106 Otherwise, <code>date</code> formats the current time. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4107 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4108 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4109 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4110 If <code>format</code> starts with '<code>!</code>', |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4111 then the date is formatted in Coordinated Universal Time. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4112 After this optional character, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4113 if <code>format</code> is the string "<code>*t</code>", |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4114 then <code>date</code> returns a table with the following fields: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4115 <code>year</code> (four digits), <code>month</code> (1–12), <code>day</code> (1–31), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4116 <code>hour</code> (0–23), <code>min</code> (0–59), <code>sec</code> (0–61), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4117 <code>wday</code> (weekday, Sunday is 1), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4118 <code>yday</code> (day of the year), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4119 and <code>isdst</code> (daylight saving flag, a boolean). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4120 This last field may be absent |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4121 if the information is not available. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4122 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4123 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4124 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4125 If <code>format</code> is not "<code>*t</code>", |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4126 then <code>date</code> returns the date as a string, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4127 formatted according to the same rules as the ISO C function <code>strftime</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4128 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4129 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4130 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4131 When called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4132 <code>date</code> returns a reasonable date and time representation that depends on |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4133 the host system and on the current locale |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4134 (that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4135 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4136 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4137 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4138 On non-POSIX systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4139 this function may be not thread safe |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4140 because of its reliance on C function <code>gmtime</code> and C function <code>localtime</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4141 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4142 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4143 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4144 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4145 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4146 <hr><h3><a name="pdf-os.difftime"><code>os.difftime (t2, t1)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4147 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4148 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4149 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4150 Returns the difference, in seconds, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4151 from time <code>t1</code> to time <code>t2</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4152 (where the times are values returned by <a href="#pdf-os.time"><code>os.time</code></a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4153 In POSIX, Windows, and some other systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4154 this value is exactly <code>t2</code><em>-</em><code>t1</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4155 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4156 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4157 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4158 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4159 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4160 <hr><h3><a name="pdf-os.execute"><code>os.execute ([command])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4161 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4162 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4163 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4164 This function is equivalent to the ISO C function <code>system</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4165 It passes <code>command</code> to be executed by an operating system shell. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4166 Its first result is <b>true</b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4167 if the command terminated successfully, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4168 or <b>nil</b> otherwise. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4169 After this first result |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4170 the function returns a string plus a number, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4171 as follows: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4172 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4173 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4174 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4175 <li><b>"<code>exit</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4176 the command terminated normally; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4177 the following number is the exit status of the command. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4178 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4179 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4180 <li><b>"<code>signal</code>": </b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4181 the command was terminated by a signal; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4182 the following number is the signal that terminated the command. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4183 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4184 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4185 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4186 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4187 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4188 When called without a <code>command</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4189 <code>os.execute</code> returns a boolean that is true if a shell is available. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4190 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4191 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4192 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4193 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4194 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4195 <hr><h3><a name="pdf-os.exit"><code>os.exit ([code [, close]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4196 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4197 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4198 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4199 Calls the ISO C function <code>exit</code> to terminate the host program. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4200 If <code>code</code> is <b>true</b>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4201 the returned status is <code>EXIT_SUCCESS</code>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4202 if <code>code</code> is <b>false</b>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4203 the returned status is <code>EXIT_FAILURE</code>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4204 if <code>code</code> is a number, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4205 the returned status is this number. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4206 The default value for <code>code</code> is <b>true</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4207 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4208 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4209 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4210 If the optional second argument <code>close</code> is true, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4211 closes the Lua state before exiting. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4212 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4213 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4214 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4215 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4216 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4217 <hr><h3><a name="pdf-os.getenv"><code>os.getenv (varname)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4218 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4219 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4220 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4221 Returns the value of the process environment variable <code>varname</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4222 or <b>nil</b> if the variable is not defined. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4223 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4224 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4225 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4226 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4227 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4228 <hr><h3><a name="pdf-os.remove"><code>os.remove (filename)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4229 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4230 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4231 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4232 Deletes the file (or empty directory, on POSIX systems) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4233 with the given name. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4234 If this function fails, it returns <b>nil</b>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4235 plus a string describing the error and the error code. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4236 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4237 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4238 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4239 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4240 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4241 <hr><h3><a name="pdf-os.rename"><code>os.rename (oldname, newname)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4242 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4243 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4244 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4245 Renames file or directory named <code>oldname</code> to <code>newname</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4246 If this function fails, it returns <b>nil</b>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4247 plus a string describing the error and the error code. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4248 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4249 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4250 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4251 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4252 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4253 <hr><h3><a name="pdf-os.setlocale"><code>os.setlocale (locale [, category])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4254 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4255 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4256 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4257 Sets the current locale of the program. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4258 <code>locale</code> is a system-dependent string specifying a locale; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4259 <code>category</code> is an optional string describing which category to change: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4260 <code>"all"</code>, <code>"collate"</code>, <code>"ctype"</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4261 <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4262 the default category is <code>"all"</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4263 The function returns the name of the new locale, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4264 or <b>nil</b> if the request cannot be honored. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4265 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4266 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4267 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4268 If <code>locale</code> is the empty string, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4269 the current locale is set to an implementation-defined native locale. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4270 If <code>locale</code> is the string "<code>C</code>", |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4271 the current locale is set to the standard C locale. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4272 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4273 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4274 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4275 When called with <b>nil</b> as the first argument, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4276 this function only returns the name of the current locale |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4277 for the given category. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4278 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4279 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4280 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4281 This function may be not thread safe |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4282 because of its reliance on C function <code>setlocale</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4283 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4284 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4285 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4286 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4287 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4288 <hr><h3><a name="pdf-os.time"><code>os.time ([table])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4289 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4290 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4291 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4292 Returns the current time when called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4293 or a time representing the date and time specified by the given table. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4294 This table must have fields <code>year</code>, <code>month</code>, and <code>day</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4295 and may have fields |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4296 <code>hour</code> (default is 12), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4297 <code>min</code> (default is 0), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4298 <code>sec</code> (default is 0), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4299 and <code>isdst</code> (default is <b>nil</b>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4300 For a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4301 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4302 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4303 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4304 The returned value is a number, whose meaning depends on your system. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4305 In POSIX, Windows, and some other systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4306 this number counts the number |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4307 of seconds since some given start time (the "epoch"). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4308 In other systems, the meaning is not specified, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4309 and the number returned by <code>time</code> can be used only as an argument to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4310 <a href="#pdf-os.date"><code>os.date</code></a> and <a href="#pdf-os.difftime"><code>os.difftime</code></a>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4311 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4312 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4313 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4314 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4315 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4316 <hr><h3><a name="pdf-os.tmpname"><code>os.tmpname ()</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4317 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4318 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4319 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4320 Returns a string with a file name that can |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4321 be used for a temporary file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4322 The file must be explicitly opened before its use |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4323 and explicitly removed when no longer needed. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4324 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4325 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4326 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4327 On POSIX systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4328 this function also creates a file with that name, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4329 to avoid security risks. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4330 (Someone else might create the file with wrong permissions |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4331 in the time between getting the name and creating the file.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4332 You still have to open the file to use it |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4333 and to remove it (even if you do not use it). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4334 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4335 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4336 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4337 When possible, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4338 you may prefer to use <a href="#pdf-io.tmpfile"><code>io.tmpfile</code></a>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4339 which automatically removes the file when the program ends. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4340 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4341 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4342 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4343 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4344 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4345 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4346 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4347 <h2>6.10 – <a name="6.10">The Debug Library</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4348 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4349 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4350 This library provides |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4351 the functionality of the debug interface (<a href="#4.9">§4.9</a>) to Lua programs. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4352 You should exert care when using this library. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4353 Several of its functions |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4354 violate basic assumptions about Lua code |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4355 (e.g., that variables local to a function |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4356 cannot be accessed from outside; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4357 that userdata metatables cannot be changed by Lua code; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4358 that Lua programs do not crash) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4359 and therefore can compromise otherwise secure code. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4360 Moreover, some functions in this library may be slow. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4361 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4362 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4363 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4364 All functions in this library are provided |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4365 inside the <a name="pdf-debug"><code>debug</code></a> table. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4366 All functions that operate over a thread |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4367 have an optional first argument which is the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4368 thread to operate over. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4369 The default is always the current thread. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4370 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4371 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4372 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4373 <hr><h3><a name="pdf-debug.debug"><code>debug.debug ()</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4374 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4375 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4376 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4377 Enters an interactive mode with the user, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4378 running each string that the user enters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4379 Using simple commands and other debug facilities, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4380 the user can inspect global and local variables, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4381 change their values, evaluate expressions, and so on. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4382 A line containing only the word <code>cont</code> finishes this function, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4383 so that the caller continues its execution. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4384 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4385 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4386 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4387 Note that commands for <code>debug.debug</code> are not lexically nested |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4388 within any function and so have no direct access to local variables. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4389 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4390 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4391 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4392 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4393 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4394 <hr><h3><a name="pdf-debug.gethook"><code>debug.gethook ([thread])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4395 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4396 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4397 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4398 Returns the current hook settings of the thread, as three values: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4399 the current hook function, the current hook mask, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4400 and the current hook count |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4401 (as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4402 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4403 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4404 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4405 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4406 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4407 <hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] f [, what])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4408 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4409 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4410 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4411 Returns a table with information about a function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4412 You can give the function directly |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4413 or you can give a number as the value of <code>f</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4414 which means the function running at level <code>f</code> of the call stack |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4415 of the given thread: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4416 level 0 is the current function (<code>getinfo</code> itself); |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4417 level 1 is the function that called <code>getinfo</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4418 (except for tail calls, which do not count on the stack); |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4419 and so on. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4420 If <code>f</code> is a number larger than the number of active functions, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4421 then <code>getinfo</code> returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4422 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4423 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4424 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4425 The returned table can contain all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4426 with the string <code>what</code> describing which fields to fill in. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4427 The default for <code>what</code> is to get all information available, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4428 except the table of valid lines. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4429 If present, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4430 the option '<code>f</code>' |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4431 adds a field named <code>func</code> with the function itself. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4432 If present, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4433 the option '<code>L</code>' |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4434 adds a field named <code>activelines</code> with the table of |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4435 valid lines. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4436 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4437 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4438 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4439 For instance, the expression <code>debug.getinfo(1,"n").name</code> returns |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4440 a table with a name for the current function, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4441 if a reasonable name can be found, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4442 and the expression <code>debug.getinfo(print)</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4443 returns a table with all available information |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4444 about the <a href="#pdf-print"><code>print</code></a> function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4445 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4446 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4447 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4448 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4449 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4450 <hr><h3><a name="pdf-debug.getlocal"><code>debug.getlocal ([thread,] f, local)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4451 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4452 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4453 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4454 This function returns the name and the value of the local variable |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4455 with index <code>local</code> of the function at level <code>f</code> of the stack. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4456 This function accesses not only explicit local variables, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4457 but also parameters, temporaries, etc. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4458 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4459 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4460 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4461 The first parameter or local variable has index 1, and so on, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4462 following the order that they are declared in the code, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4463 counting only the variables that are active |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4464 in the current scope of the function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4465 Negative indices refer to vararg parameters; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4466 -1 is the first vararg parameter. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4467 The function returns <b>nil</b> if there is no variable with the given index, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4468 and raises an error when called with a level out of range. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4469 (You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the level is valid.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4470 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4471 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4472 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4473 Variable names starting with '<code>(</code>' (open parenthesis) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4474 represent variables with no known names |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4475 (internal variables such as loop control variables, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4476 and variables from chunks saved without debug information). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4477 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4478 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4479 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4480 The parameter <code>f</code> may also be a function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4481 In that case, <code>getlocal</code> returns only the name of function parameters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4482 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4483 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4484 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4485 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4486 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4487 <hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (value)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4488 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4489 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4490 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4491 Returns the metatable of the given <code>value</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4492 or <b>nil</b> if it does not have a metatable. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4493 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4494 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4495 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4496 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4497 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4498 <hr><h3><a name="pdf-debug.getregistry"><code>debug.getregistry ()</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4499 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4500 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4501 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4502 Returns the registry table (see <a href="#4.5">§4.5</a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4503 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4504 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4505 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4506 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4507 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4508 <hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (f, up)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4509 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4510 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4511 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4512 This function returns the name and the value of the upvalue |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4513 with index <code>up</code> of the function <code>f</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4514 The function returns <b>nil</b> if there is no upvalue with the given index. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4515 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4516 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4517 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4518 Variable names starting with '<code>(</code>' (open parenthesis) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4519 represent variables with no known names |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4520 (variables from chunks saved without debug information). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4521 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4522 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4523 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4524 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4525 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4526 <hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4527 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4528 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4529 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4530 Returns the Lua value associated to <code>u</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4531 If <code>u</code> is not a userdata, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4532 returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4533 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4534 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4535 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4536 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4537 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4538 <hr><h3><a name="pdf-debug.sethook"><code>debug.sethook ([thread,] hook, mask [, count])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4539 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4540 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4541 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4542 Sets the given function as a hook. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4543 The string <code>mask</code> and the number <code>count</code> describe |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4544 when the hook will be called. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4545 The string mask may have any combination of the following characters, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4546 with the given meaning: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4547 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4548 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4549 <li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4550 <li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4551 <li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4552 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4553 Moreover, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4554 with a <code>count</code> different from zero, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4555 the hook is called also after every <code>count</code> instructions. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4556 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4557 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4558 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4559 When called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4560 <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> turns off the hook. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4561 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4562 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4563 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4564 When the hook is called, its first parameter is a string |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4565 describing the event that has triggered its call: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4566 <code>"call"</code> (or <code>"tail call"</code>), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4567 <code>"return"</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4568 <code>"line"</code>, and <code>"count"</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4569 For line events, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4570 the hook also gets the new line number as its second parameter. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4571 Inside a hook, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4572 you can call <code>getinfo</code> with level 2 to get more information about |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4573 the running function |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4574 (level 0 is the <code>getinfo</code> function, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4575 and level 1 is the hook function). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4576 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4577 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4578 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4579 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4580 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4581 <hr><h3><a name="pdf-debug.setlocal"><code>debug.setlocal ([thread,] level, local, value)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4582 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4583 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4584 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4585 This function assigns the value <code>value</code> to the local variable |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4586 with index <code>local</code> of the function at level <code>level</code> of the stack. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4587 The function returns <b>nil</b> if there is no local |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4588 variable with the given index, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4589 and raises an error when called with a <code>level</code> out of range. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4590 (You can call <code>getinfo</code> to check whether the level is valid.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4591 Otherwise, it returns the name of the local variable. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4592 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4593 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4594 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4595 See <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for more information about |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4596 variable indices and names. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4597 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4598 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4599 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4600 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4601 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4602 <hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (value, table)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4603 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4604 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4605 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4606 Sets the metatable for the given <code>value</code> to the given <code>table</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4607 (which can be <b>nil</b>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4608 Returns <code>value</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4609 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4610 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4611 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4612 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4613 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4614 <hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (f, up, value)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4615 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4616 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4617 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4618 This function assigns the value <code>value</code> to the upvalue |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4619 with index <code>up</code> of the function <code>f</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4620 The function returns <b>nil</b> if there is no upvalue |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4621 with the given index. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4622 Otherwise, it returns the name of the upvalue. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4623 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4624 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4625 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4626 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4627 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4628 <hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4629 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4630 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4631 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4632 Sets the given <code>value</code> as |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4633 the Lua value associated to the given <code>udata</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4634 <code>udata</code> must be a full userdata. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4635 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4636 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4637 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4638 Returns <code>udata</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4639 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4640 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4641 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4642 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4643 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4644 <hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4645 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4646 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4647 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4648 If <code>message</code> is present but is neither a string nor <b>nil</b>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4649 this function returns <code>message</code> without further processing. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4650 Otherwise, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4651 it returns a string with a traceback of the call stack. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4652 The optional <code>message</code> string is appended |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4653 at the beginning of the traceback. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4654 An optional <code>level</code> number tells at which level |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4655 to start the traceback |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4656 (default is 1, the function calling <code>traceback</code>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4657 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4658 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4659 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4660 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4661 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4662 <hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (f, n)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4663 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4664 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4665 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4666 Returns a unique identifier (as a light userdata) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4667 for the upvalue numbered <code>n</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4668 from the given function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4669 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4670 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4671 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4672 These unique identifiers allow a program to check whether different |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4673 closures share upvalues. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4674 Lua closures that share an upvalue |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4675 (that is, that access a same external local variable) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4676 will return identical ids for those upvalue indices. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4677 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4678 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4679 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4680 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4681 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4682 <hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4683 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4684 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4685 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4686 Make the <code>n1</code>-th upvalue of the Lua closure <code>f1</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4687 refer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4688 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4689 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4690 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4691 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4692 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4693 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4694 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4695 <h1>7 – <a name="7">Lua Standalone</a></h1> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4696 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4697 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4698 Although Lua has been designed as an extension language, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4699 to be embedded in a host C program, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4700 it is also frequently used as a standalone language. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4701 An interpreter for Lua as a standalone language, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4702 called simply <code>lua</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4703 is provided with the standard distribution. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4704 The standalone interpreter includes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4705 all standard libraries, including the debug library. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4706 Its usage is: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4707 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4708 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4709 lua [options] [script [args]] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4710 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4711 The options are: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4712 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4713 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4714 <li><b><code>-e <em>stat</em></code>: </b> executes string <em>stat</em>;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4715 <li><b><code>-l <em>mod</em></code>: </b> "requires" <em>mod</em>;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4716 <li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4717 <li><b><code>-v</code>: </b> prints version information;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4718 <li><b><code>-E</code>: </b> ignores environment variables;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4719 <li><b><code>--</code>: </b> stops handling options;</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4720 <li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4721 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4722 After handling its options, <code>lua</code> runs the given <em>script</em>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4723 When called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4724 <code>lua</code> behaves as <code>lua -v -i</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4725 when the standard input (<code>stdin</code>) is a terminal, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4726 and as <code>lua -</code> otherwise. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4727 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4728 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4729 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4730 When called without option <code>-E</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4731 the interpreter checks for an environment variable <a name="pdf-LUA_INIT_5_3"><code>LUA_INIT_5_3</code></a> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4732 (or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if the versioned name is not defined) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4733 before running any argument. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4734 If the variable content has the format <code>@<em>filename</em></code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4735 then <code>lua</code> executes the file. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4736 Otherwise, <code>lua</code> executes the string itself. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4737 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4738 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4739 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4740 When called with option <code>-E</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4741 besides ignoring <code>LUA_INIT</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4742 Lua also ignores |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4743 the values of <code>LUA_PATH</code> and <code>LUA_CPATH</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4744 setting the values of |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4745 <a href="#pdf-package.path"><code>package.path</code></a> and <a href="#pdf-package.cpath"><code>package.cpath</code></a> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4746 with the default paths defined in <code>luaconf.h</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4747 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4748 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4749 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4750 All options are handled in order, except <code>-i</code> and <code>-E</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4751 For instance, an invocation like |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4752 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4753 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4754 $ lua -e'a=1' -e 'print(a)' script.lua |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4755 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4756 will first set <code>a</code> to 1, then print the value of <code>a</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4757 and finally run the file <code>script.lua</code> with no arguments. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4758 (Here <code>$</code> is the shell prompt. Your prompt may be different.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4759 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4760 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4761 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4762 Before running any code, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4763 <code>lua</code> collects all command-line arguments |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4764 in a global table called <code>arg</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4765 The script name goes to index 0, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4766 the first argument after the script name goes to index 1, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4767 and so on. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4768 Any arguments before the script name |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4769 (that is, the interpreter name plus its options) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4770 go to negative indices. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4771 For instance, in the call |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4772 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4773 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4774 $ lua -la b.lua t1 t2 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4775 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4776 the table is like this: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4777 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4778 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4779 arg = { [-2] = "lua", [-1] = "-la", |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4780 [0] = "b.lua", |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4781 [1] = "t1", [2] = "t2" } |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4782 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4783 If there is no script in the call, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4784 the interpreter name goes to index 0, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4785 followed by the other arguments. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4786 For instance, the call |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4787 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4788 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4789 $ lua -e "print(arg[1])" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4790 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4791 will print "<code>-e</code>". |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4792 If there is a script, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4793 the script is called with parameters |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4794 <code>arg[1]</code>, ···, <code>arg[#arg]</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4795 (Like all chunks in Lua, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4796 the script is compiled as a vararg function.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4797 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4798 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4799 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4800 In interactive mode, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4801 Lua repeatedly prompts and waits for a line. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4802 After reading a line, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4803 Lua first try to interpret the line as an expression. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4804 If it succeeds, it prints its value. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4805 Otherwise, it interprets the line as a statement. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4806 If you write an incomplete statement, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4807 the interpreter waits for its completion |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4808 by issuing a different prompt. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4809 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4810 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4811 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4812 In case of unprotected errors in the script, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4813 the interpreter reports the error to the standard error stream. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4814 If the error object is not a string but |
429
e3a6d9dbd694
rename __tostring to __to_string
Franklin Schmidt <fschmidt@gmail.com>
parents:
428
diff
changeset
|
4815 has a metamethod <code>__to_string</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4816 the interpreter calls this metamethod to produce the final message. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4817 Otherwise, the interpreter converts the error object to a string |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4818 and adds a stack traceback to it. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4819 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4820 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4821 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4822 When finishing normally, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4823 the interpreter closes its main Lua state |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4824 (see <a href="#lua_close"><code>lua_close</code></a>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4825 The script can avoid this step by |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4826 calling <a href="#pdf-os.exit"><code>os.exit</code></a> to terminate. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4827 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4828 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4829 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4830 To allow the use of Lua as a |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4831 script interpreter in Unix systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4832 the standalone interpreter skips |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4833 the first line of a chunk if it starts with <code>#</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4834 Therefore, Lua scripts can be made into executable programs |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4835 by using <code>chmod +x</code> and the <code>#!</code> form, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4836 as in |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4837 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4838 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4839 #!/usr/local/bin/lua |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4840 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4841 (Of course, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4842 the location of the Lua interpreter may be different in your machine. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4843 If <code>lua</code> is in your <code>PATH</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4844 then |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4845 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4846 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4847 #!/usr/bin/env lua |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4848 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4849 is a more portable solution.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4850 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4851 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4852 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4853 <h1>8 – <a name="8">Incompatibilities with the Previous Version</a></h1> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4854 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4855 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4856 Here we list the incompatibilities that you may find when moving a program |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4857 from Lua 5.2 to Lua 5.3. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4858 You can avoid some incompatibilities by compiling Lua with |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4859 appropriate options (see file <code>luaconf.h</code>). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4860 However, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4861 all these compatibility options will be removed in the future. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4862 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4863 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4864 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4865 Lua versions can always change the C API in ways that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4866 do not imply source-code changes in a program, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4867 such as the numeric values for constants |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4868 or the implementation of functions as macros. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4869 Therefore, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4870 you should not assume that binaries are compatible between |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4871 different Lua versions. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4872 Always recompile clients of the Lua API when |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4873 using a new version. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4874 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4875 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4876 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4877 Similarly, Lua versions can always change the internal representation |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4878 of precompiled chunks; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4879 precompiled chunks are not compatible between different Lua versions. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4880 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4881 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4882 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4883 The standard paths in the official distribution may |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4884 change between versions. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4885 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4886 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4887 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4888 <h2>8.1 – <a name="8.1">Changes in the Language</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4889 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4890 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4891 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4892 The main difference between Lua 5.2 and Lua 5.3 is the |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4893 introduction of an integer subtype for numbers. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4894 Although this change should not affect "normal" computations, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4895 some computations |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4896 (mainly those that involve some kind of overflow) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4897 can give different results. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4898 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4899 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4900 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4901 You can fix these differences by forcing a number to be a float |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4902 (in Lua 5.2 all numbers were float), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4903 in particular writing constants with an ending <code>.0</code> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4904 or using <code>x = x + 0.0</code> to convert a variable. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4905 (This recommendation is only for a quick fix |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4906 for an occasional incompatibility; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4907 it is not a general guideline for good programming. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4908 For good programming, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4909 use floats where you need floats |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4910 and integers where you need integers.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4911 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4912 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4913 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4914 The conversion of a float to a string now adds a <code>.0</code> suffix |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4915 to the result if it looks like an integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4916 (For instance, the float 2.0 will be printed as <code>2.0</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4917 not as <code>2</code>.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4918 You should always use an explicit format |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4919 when you need a specific format for numbers. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4920 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4921 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4922 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4923 (Formally this is not an incompatibility, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4924 because Lua does not specify how numbers are formatted as strings, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4925 but some programs assumed a specific format.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4926 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4927 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4928 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4929 The generational mode for the garbage collector was removed. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4930 (It was an experimental feature in Lua 5.2.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4931 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4932 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4933 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4934 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4935 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4936 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4937 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4938 <h2>8.2 – <a name="8.2">Changes in the Libraries</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4939 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4940 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4941 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4942 The <code>bit32</code> library has been deprecated. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4943 It is easy to require a compatible external library or, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4944 better yet, to replace its functions with appropriate bitwise operations. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4945 (Keep in mind that <code>bit32</code> operates on 32-bit integers, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4946 while the bitwise operators in standard Lua operate on 64-bit integers.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4947 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4948 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4949 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4950 The Table library now respects metamethods |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4951 for setting and getting elements. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4952 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4953 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4954 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4955 The <a href="#pdf-ipairs"><code>ipairs</code></a> iterator now respects metamethods and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4956 its <code>__ipairs</code> metamethod has been deprecated. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4957 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4958 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4959 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4960 Option names in <a href="#pdf-io.read"><code>io.read</code></a> do not have a starting '<code>*</code>' anymore. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4961 For compatibility, Lua will continue to ignore this character. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4962 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4963 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4964 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4965 The following functions were deprecated in the mathematical library: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4966 <code>atan2</code>, <code>cosh</code>, <code>sinh</code>, <code>tanh</code>, <code>pow</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4967 <code>frexp</code>, and <code>ldexp</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4968 You can replace <code>math.pow(x,y)</code> with <code>x^y</code>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4969 you can replace <code>math.atan2</code> with <code>math.atan</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4970 which now accepts one or two parameters; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4971 you can replace <code>math.ldexp(x,exp)</code> with <code>x * 2.0^exp</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4972 For the other operations, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4973 you can either use an external library or |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4974 implement them in Lua. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4975 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4976 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4977 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4978 The searcher for C loaders used by <a href="#pdf-require"><code>require</code></a> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4979 changed the way it handles versioned names. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4980 Now, the version should come after the module name |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4981 (as is usual in most other tools). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4982 For compatibility, that searcher still tries the old format |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4983 if it cannot find an open function according to the new style. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4984 (Lua 5.2 already worked that way, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4985 but it did not document the change.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4986 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4987 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4988 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4989 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4990 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4991 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4992 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4993 <h2>8.3 – <a name="8.3">Changes in the API</a></h2> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4994 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4995 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4996 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4997 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4998 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4999 Continuation functions now receive as parameters what they needed |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5000 to get through <code>lua_getctx</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5001 so <code>lua_getctx</code> has been removed. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5002 Adapt your code accordingly. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5003 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5004 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5005 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5006 Function <a href="#lua_dump"><code>lua_dump</code></a> has an extra parameter, <code>strip</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5007 Use 0 as the value of this parameter to get the old behavior. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5008 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5009 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5010 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5011 Functions to inject/project unsigned integers |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5012 (<code>lua_pushunsigned</code>, <code>lua_tounsigned</code>, <code>lua_tounsignedx</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5013 <code>luaL_checkunsigned</code>, <code>luaL_optunsigned</code>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5014 were deprecated. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5015 Use their signed equivalents with a type cast. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5016 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5017 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5018 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5019 Macros to project non-default integer types |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5020 (<code>luaL_checkint</code>, <code>luaL_optint</code>, <code>luaL_checklong</code>, <code>luaL_optlong</code>) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5021 were deprecated. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5022 Use their equivalent over <a href="#lua_Integer"><code>lua_Integer</code></a> with a type cast |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5023 (or, when possible, use <a href="#lua_Integer"><code>lua_Integer</code></a> in your code). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5024 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5025 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5026 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5027 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5028 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5029 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5030 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5031 <h1>9 – <a name="9">The Complete Syntax of Lua</a></h1> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5032 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5033 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5034 Here is the complete syntax of Lua in extended BNF. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5035 As usual in extended BNF, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5036 {A} means 0 or more As, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5037 and [A] means an optional A. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5038 (For operator precedences, see <a href="#3.4.8">§3.4.8</a>; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5039 for a description of the terminals |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5040 Name, Numeral, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5041 and LiteralString, see <a href="#3.1">§3.1</a>.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5042 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5043 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5044 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5045 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5046 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5047 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5048 chunk ::= block |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5049 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5050 block ::= {stat} [retstat] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5051 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5052 stat ::= ‘<b>;</b>’ | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5053 varlist ‘<b>=</b>’ explist | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5054 functioncall | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5055 label | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5056 <b>break</b> | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5057 <b>goto</b> Name | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5058 <b>do</b> block <b>end</b> | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5059 <b>while</b> exp <b>do</b> block <b>end</b> | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5060 <b>repeat</b> block <b>until</b> exp | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5061 <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5062 <b>for</b> Name ‘<b>=</b>’ exp ‘<b>,</b>’ exp [‘<b>,</b>’ exp] <b>do</b> block <b>end</b> | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5063 <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5064 <b>function</b> funcname funcbody | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5065 <b>local</b> <b>function</b> Name funcbody | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5066 <b>local</b> namelist [‘<b>=</b>’ explist] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5067 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5068 retstat ::= <b>return</b> [explist] [‘<b>;</b>’] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5069 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5070 label ::= ‘<b>::</b>’ Name ‘<b>::</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5071 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5072 funcname ::= Name {‘<b>.</b>’ Name} [‘<b>:</b>’ Name] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5073 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5074 varlist ::= var {‘<b>,</b>’ var} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5075 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5076 var ::= Name | prefixexp ‘<b>[</b>’ exp ‘<b>]</b>’ | prefixexp ‘<b>.</b>’ Name |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5077 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5078 namelist ::= Name {‘<b>,</b>’ Name} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5079 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5080 explist ::= exp {‘<b>,</b>’ exp} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5081 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5082 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Numeral | LiteralString | ‘<b>...</b>’ | functiondef | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5083 prefixexp | tableconstructor | exp binop exp | unop exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5084 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5085 prefixexp ::= var | functioncall | ‘<b>(</b>’ exp ‘<b>)</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5086 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5087 functioncall ::= prefixexp args | prefixexp ‘<b>:</b>’ Name args |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5088 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5089 args ::= ‘<b>(</b>’ [explist] ‘<b>)</b>’ | tableconstructor | LiteralString |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5090 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5091 functiondef ::= <b>function</b> funcbody |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5092 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5093 funcbody ::= ‘<b>(</b>’ [parlist] ‘<b>)</b>’ block <b>end</b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5094 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5095 parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5096 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5097 tableconstructor ::= ‘<b>{</b>’ [fieldlist] ‘<b>}</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5098 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5099 fieldlist ::= field {fieldsep field} [fieldsep] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5100 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5101 field ::= ‘<b>[</b>’ exp ‘<b>]</b>’ ‘<b>=</b>’ exp | Name ‘<b>=</b>’ exp | exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5102 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5103 fieldsep ::= ‘<b>,</b>’ | ‘<b>;</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5104 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5105 binop ::= ‘<b>+</b>’ | ‘<b>-</b>’ | ‘<b>*</b>’ | ‘<b>/</b>’ | ‘<b>//</b>’ | ‘<b>^</b>’ | ‘<b>%</b>’ | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5106 ‘<b>&</b>’ | ‘<b>~</b>’ | ‘<b>|</b>’ | ‘<b>>></b>’ | ‘<b><<</b>’ | ‘<b>..</b>’ | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5107 ‘<b><</b>’ | ‘<b><=</b>’ | ‘<b>></b>’ | ‘<b>>=</b>’ | ‘<b>==</b>’ | ‘<b>~=</b>’ | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5108 <b>and</b> | <b>or</b> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5109 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5110 unop ::= ‘<b>-</b>’ | <b>not</b> | ‘<b>#</b>’ | ‘<b>~</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5111 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5112 </pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5113 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5114 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5115 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5116 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5117 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5118 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5119 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5120 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5121 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5122 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5123 <HR> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5124 <SMALL CLASS="footer"> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5125 Last update: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5126 Fri Jan 16 00:58:20 BRST 2015 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5127 </SMALL> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5128 <!-- |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5129 Last change: minor edit |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5130 --> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5131 |
372 | 5132 </div> |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
5133 |
391
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
5134 <% Html.simply_html_body_bottom() %> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
5135 </body> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
5136 </html> |
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
389
diff
changeset
|
5137 <% |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
5138 end |