Mercurial Hosting > luan
annotate website/src/manual.html.luan @ 579:f22a09e98b04
clean up LuanState
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 16 Jul 2015 15:14:31 -0600 |
parents | 6c00b8a59240 |
children | 1e69d9c21461 |
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" |
494
2b9bc97f0439
change luan:web to luan:http
Franklin Schmidt <fschmidt@gmail.com>
parents:
492
diff
changeset
|
4 local Http = require "luan:http/Http" |
387
23d075ce1e48
add website/src/Shared.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
386
diff
changeset
|
5 local Shared = require "site:/Shared" |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
6 |
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
7 |
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
8 return function() |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
9 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
|
10 %> |
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 <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
|
12 <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
|
13 <title>Luan Reference Manual</title> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
14 <style> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
15 @import "/site.css"; |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
16 </style> |
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
|
17 </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
|
18 <body> |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
19 |
372 | 20 <div container> |
387
23d075ce1e48
add website/src/Shared.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
386
diff
changeset
|
21 <% Shared.header() %> |
372 | 22 |
23 <h1>Luan Reference Manual</h1> | |
24 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
25 <p 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. | |
30 </p> | |
31 | |
32 <hr/> | |
33 | |
34 <h2>Contents</h2> | |
35 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
36 <div contents><a href="#intro">Introduction</a></div> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
37 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
38 <div contents> |
373 | 39 <a href="#basic">Basic Concepts</a> |
40 <ul> | |
41 <li><a href="#types">Values and Types</a></li> | |
42 <li><a href="#env">Environments</a></li> | |
43 <li><a href="#error">Error Handling</a></li> | |
44 <li><a href="#meta">Metatables and Metamethods</a></li> | |
380 | 45 <li><a href="#gc">Garbage Collection</a></li> |
46 </ul> | |
47 </div> | |
48 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
49 <div contents> |
380 | 50 <a href="#lang">The Language</a> |
51 <ul> | |
52 <li><a href="#lex">Lexical Conventions</a></li> | |
53 <li><a href="#vars">Variables</a></li> | |
389 | 54 <li> |
55 <a href="#stmts">Statements</a> | |
56 <ul> | |
57 <li><a href="#blocks">Blocks</a></li> | |
395 | 58 <li><a href="#chunks">Chunks</a></li> |
59 <li><a href="#assignment">Assignment</a></li> | |
60 <li><a href="#control">Control Structures</a></li> | |
61 <li><a href="#for">For Statement</a></li> | |
62 <li><a href="#fn_stmt">Function Calls as Statements</a></li> | |
63 <li><a href="#local_stmt">Local Declarations</a></li> | |
465 | 64 <li><a href="#template_stmt">Template Statements</a></li> |
395 | 65 </ul> |
66 </li> | |
67 <li> | |
68 <a href="#expressions">Expressions</a> | |
69 <ul> | |
70 <li><a href="#arithmetic">Arithmetic Operators</a></li> | |
396 | 71 <li><a href="#conversions">Coercions and Conversions</a></li> |
72 <li><a href="#relational">Relational Operators</a></li> | |
73 <li><a href="#logical_ops">Logical Operators</a></li> | |
74 <li><a href="#concatenation">Concatenation</a></li> | |
75 <li><a href="#length">The Length Operator</a></li> | |
76 <li><a href="#precedence">Precedence</a></li> | |
77 <li><a href="#constructors">Table Constructors</a></li> | |
417 | 78 <li><a href="#fn_calls">Function Calls</a></li> |
79 <li><a href="#fn_def">Function Definitions</a></li> | |
465 | 80 <li><a href="#template_expr">Template Expressions</a></li> |
389 | 81 </ul> |
82 </li> | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
83 <li><a href="#visibility">Visibility Rules</a></li> |
373 | 84 </ul> |
85 </div> | |
86 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
87 <div contents> |
468 | 88 <a href="#libs">Standard Libraries</a> |
89 <ul> | |
90 <li><a href="#default_lib">Default Environment</a></li> | |
470 | 91 <li><a href="#luan_lib">Basic Functions</a></li> |
476 | 92 <li><a href="#package_lib">Modules</a></li> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
93 <li><a href="#string_lib">String Manipulation</a></li> |
567 | 94 <li><a href="#binary_lib">Binary Manipulation</a></li> |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
95 <li><a href="#table_lib">Table Manipulation</a></li> |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
96 <li><a href="#number_lib">Number Manipulation</a></li> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
97 <li><a href="#math_lib">Mathematical Functions</a></li> |
468 | 98 </ul> |
99 </div> | |
100 | |
372 | 101 <hr/> |
102 | |
373 | 103 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
104 <h2 heading><a name="intro">Introduction</a></h2> |
372 | 105 |
106 <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> | |
107 | |
108 <p>Luan is implemented in Java and is tightly coupled with Java. So it makes a great scripting language for Java programmers.</p> | |
109 | |
110 <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
|
111 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
112 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
113 <h2 heading><a name="basic">Basic Concepts</a></h2> |
373 | 114 |
115 <p>This section describes the basic concepts of the language.</p> | |
116 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
117 <h3 heading><a name="types">Values and Types</a></h3> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
118 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
119 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
120 Luan is a <em>dynamically typed language</em>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
121 This means that |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
126 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
127 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
128 All values in Luan are <em>first-class values</em>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
129 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
|
130 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
|
131 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
132 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
133 <p> |
373 | 134 There are eight basic types in Luan: |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
135 <em>nil</em>, <em>boolean</em>, <em>number</em>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
136 <em>string</em>, <em>binary</em>, <em>function</em>, <em>java</em>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
137 and <em>table</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
138 <em>Nil</em> 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
|
139 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
|
140 it usually represents the absence of a useful value. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
141 <em>Nil</em> is implemented as the Java value <em>null</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
142 <em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
143 <em>Boolean</em> is implemented as the Java class <em>Boolean</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
144 <em>Number</em> represents both |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
145 integer numbers and real (floating-point) numbers. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
146 <em>Number</em> is implemented as the Java class <em>Number</em>. Any Java subclass of <em>Number</em> is allowed and this is invisible to the Luan user. Operations on numbers follow the same rules of |
373 | 147 the underlying Java implementation. |
148 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
149 <em>String</em> is implemented as the Java class <em>String</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
150 <em>Binary</em> is implemented as the Java type <em>byte[]</em>. |
373 | 151 |
152 | |
153 <p> | |
154 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
|
155 functions written in Java (see <a href="#fn_calls">Function Calls</a>). |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
156 Both are represented by the type <em>function</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
157 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
158 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
159 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
160 The type <em>java</em> is provided to allow arbitrary Java objects to |
373 | 161 be stored in Luan variables. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
162 A <em>java</em> value is a Java object that isn't one of the standard Luan types. |
513
0dfc01d8d42d
rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents:
512
diff
changeset
|
163 Java values have 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
|
164 except assignment and identity test. |
513
0dfc01d8d42d
rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents:
512
diff
changeset
|
165 Java values are useful when Java access is enabled in Luan |
373 | 166 |
167 | |
168 | |
169 <p> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
170 The type <em>table</em> implements associative arrays, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
171 that is, arrays that can be indexed not only with numbers, |
373 | 172 but with any Luan value except <b>nil</b>. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
173 Tables can be <em>heterogeneous</em>; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 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
|
178 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
179 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
180 <p> |
373 | 181 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
|
182 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
|
183 symbol tables, sets, records, graphs, trees, etc. |
373 | 184 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
|
185 The language supports this representation by |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
186 providing <code>a.name</code> as syntactic sugar for <code>a["name"]</code>. |
373 | 187 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
|
188 (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
|
189 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
190 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
191 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
192 We use the term <em>sequence</em> to denote a table where |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
193 the set of all positive numeric keys is equal to {1..<em>n</em>} |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
194 for some non-negative integer <em>n</em>, |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
195 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
|
196 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
197 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
198 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
199 Like indices, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
200 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
|
201 In particular, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
202 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
|
203 table fields can contain functions. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
204 Thus tables can also carry <em>methods</em> (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
|
205 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
206 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
207 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
208 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
|
209 the definition of raw equality in the language. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
210 The expressions <code>a[i]</code> and <code>a[j]</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
211 denote the same table element |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
212 if and only if <code>i</code> and <code>j</code> are raw equal |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
213 (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
|
214 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
|
215 are equal to their respective integers |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
216 (e.g., <code>1.0 == 1</code>). |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
217 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
218 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
219 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
220 Luan values are <em>objects</em>: |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
221 variables do not actually <em>contain</em> values, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
222 only <em>references</em> to them. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
223 Assignment, parameter passing, and function returns |
373 | 224 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
|
225 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
|
226 |
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 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
229 The library function <a href="#Luan.type"><code>Luan.type</code></a> returns a string describing the type |
478 | 230 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
|
231 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
232 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
235 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
236 <h3 heading><a name="env">Environments</a></h3> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
237 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
238 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
239 The environment of a chunk starts with only two local variables: <code><a href="#require">require</a></code> and <code><a href="#java">java</a></code>. These are functions are used to load and access libraries and other modules. All other variables must be added to the environment using <a href="http://localhost:8080/manual.html#local_stmt">local declarations</a>. |
512
d96944467ffc
update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
505
diff
changeset
|
240 |
d96944467ffc
update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
505
diff
changeset
|
241 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
242 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
|
243 any reference to a free name |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
244 (that is, a name not bound to any declaration) <code>var</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
245 can be syntactically translated to <code>_ENV.var</code> if <code>_ENV</code> is defined. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
246 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
247 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
248 <h3 heading><a name="error">Error Handling</a></h3> |
373 | 249 |
250 <p> | |
251 Luan code can explicitly generate an error by calling the | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
252 <a href="#Luan.error"><code>error</code></a> function. |
373 | 253 If you need to catch errors in Luan, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
254 you can use <a href="#Luan.pcall"><code>pcall</code></a> or <a href="#Luan.try"><code>try</code></a> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
255 to call a given function in <em>protected mode</em>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
256 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
257 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
258 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
259 Whenever there is an error, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
260 an <em>error table</em> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
261 is propagated with information about the error. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
262 See <a href="#Luan.new_error"><code>Luan.new_error</code></a>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
263 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
264 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
265 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
266 <h3 heading><a name="meta">Metatables and Metamethods</a></h3> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
267 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
268 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
269 Every table in Luan can have a <em>metatable</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
270 This <em>metatable</em> 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
|
271 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
|
272 under certain special operations. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
273 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
|
274 of operations over a value by setting specific fields in its metatable. |
373 | 275 For instance, when a table is the operand of an addition, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
276 Luan checks for a function in the field "<code>__add</code>" 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
|
277 If it finds one, |
373 | 278 Luan calls this function to perform the addition. |
279 | |
280 | |
281 <p> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
282 The keys in a metatable are derived from the <em>event</em> names; |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
283 the corresponding values are called <ii>metamethods</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
284 In the previous example, the event is <code>"add"</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
285 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
|
286 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
287 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
288 <p> |
373 | 289 You can query the metatable of any table |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
290 using the <a href="#Luan.get_metatable"><code>get_metatable</code></a> function. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
291 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
292 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
293 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
294 You can replace the metatable of tables |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
295 using the <a href="#Luan.set_metatable"><code>set_metatable</code></a> function. |
373 | 296 |
297 | |
298 <p> | |
299 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
|
300 arithmetic operations, bitwise operations, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
301 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
|
302 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
303 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
304 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
305 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
|
306 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
|
307 The key for each event is a string with its name prefixed by |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
308 two underscores, '<code>__</code>'; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
309 for instance, the key for operation "add" is the |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
310 string "<code>__add</code>". |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
311 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
|
312 the access to a metamethod does not invoke other metamethods. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
313 You can emulate how Luan queries a metamethod for an object <code>obj</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
314 with the following code: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
315 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
316 <pre> |
373 | 317 raw_get(get_metatable(obj) or {}, "__" .. event_name) |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
318 </pre> |
373 | 319 |
320 <p> | |
321 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
|
322 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
323 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
324 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
325 <li><p><b>"add": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
326 the <code>+</code> operation. |
373 | 327 |
328 If any operand for an addition is a table, | |
329 Luan will try to call a metamethod. | |
330 First, Luan will check the first operand (even if it is valid). | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
331 If that operand does not define a metamethod for the "<code>__add</code>" event, |
373 | 332 then Luan will check the second operand. |
333 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
|
334 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
|
335 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
|
336 (adjusted to one value) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
337 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
|
338 Otherwise, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
339 it raises an error. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
340 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
341 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
342 <li><p><b>"sub": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
343 the <code>-</code> operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
344 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
345 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
|
346 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
347 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
348 <li><p><b>"mul": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
349 the <code>*</code> operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
350 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
351 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
|
352 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
353 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
354 <li><p><b>"div": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
355 the <code>/</code> operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
356 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
357 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
|
358 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
359 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
360 <li><p><b>"mod": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
361 the <code>%</code> operation. |
371
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 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
|
364 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
365 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
366 <li><p><b>"pow": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
367 the <code>^</code> (exponentiation) operation. |
371
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 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
|
370 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
371 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
372 <li><p><b>"unm": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
373 the <code>-</code> (unary minus) operation. |
371
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 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
|
376 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
377 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
378 <li><p><b>"concat": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
379 the <code>..</code> (concatenation) operation. |
373 | 380 |
381 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
|
382 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
383 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
384 <li><p><b>"len": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
385 the <code>#</code> (length) operation. |
373 | 386 |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
387 If there is a metamethod, |
373 | 388 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
|
389 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
|
390 (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
|
391 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
|
392 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
|
393 then Luan uses the table length operation (see <a href="#length">The Length Operator</a>). |
373 | 394 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
|
395 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
396 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
397 <li><p><b>"eq": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
398 the <code>==</code> (equal) operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
399 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
400 Behavior similar to the "add" operation, |
373 | 401 except that Luan will try a metamethod only when the values |
402 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
|
403 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
|
404 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
|
405 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
406 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
407 <li><p><b>"lt": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
408 the <code><</code> (less than) operation. |
373 | 409 |
410 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
|
411 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
|
412 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
413 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
414 <li><p><b>"le": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
415 the <code><=</code> (less equal) operation. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
416 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
417 Unlike other operations, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
418 The less-equal operation can use two different events. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
419 First, Luan looks for the "<code>__le</code>" 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
|
420 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
|
421 If it cannot find such a metamethod, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
422 then it will try the "<code>__lt</code>" event, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
423 assuming that <code>a <= b</code> is equivalent to <code>not (b < a)</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
424 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
|
425 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
|
426 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
427 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
428 <li><p><b>"index": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
429 The indexing access <code>table[key]</code>. |
373 | 430 |
431 This event happens | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
432 when <code>key</code> is not present in <code>table</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
433 The metamethod is looked up in <code>table</code>. |
371
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
436 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
437 Despite the name, |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
438 the metamethod for this event can be any type. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
439 If it is a function, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
440 it is called with <code>table</code> and <code>key</code> as arguments. |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
441 Otherwise |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
442 the final result is the result of indexing this metamethod object with <code>key</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
443 (This indexing is regular, not raw, |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
444 and therefore can trigger another metamethod if the metamethod object is a table.) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
445 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
446 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
447 <li><p><b>"new_index": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
448 The indexing assignment <code>table[key] = value</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
449 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
450 Like the index event, |
373 | 451 this event happens when |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
452 when <code>key</code> is not present in <code>table</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
453 The metamethod is looked up in <code>table</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
454 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
457 Like with indexing, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
458 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
|
459 If it is a function, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
460 it is called with <code>table</code>, <code>key</code>, and <code>value</code> as arguments. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
461 If it is a table, |
373 | 462 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
|
463 (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
|
464 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
|
465 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
466 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
467 <p> |
428
df95199ca4c0
rename __newindex to __new_index
Franklin Schmidt <fschmidt@gmail.com>
parents:
418
diff
changeset
|
468 Whenever there is a "new_index" metamethod, |
373 | 469 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
|
470 (If necessary, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
471 the metamethod itself can call <a href="#Luan.raw_set"><code>raw_set</code></a> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
472 to do the assignment.) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
473 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
474 |
502
d3183a330ff5
improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents:
495
diff
changeset
|
475 <li><p><b>"call": </b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
476 The call operation <code>func(args)</code>. |
373 | 477 |
478 This event happens when Luan tries to call a table. | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
479 The metamethod is looked up in <code>func</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
480 If present, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
481 the metamethod is called with <code>func</code> as its first argument, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
482 followed by the arguments of the original call (<code>args</code>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
483 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
484 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
485 </ul> |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
489 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
490 <h3 heading><a name="gc">Garbage Collection</a></h3> |
380 | 491 |
492 <p> | |
493 Luan uses Java's garbage collection. | |
494 | |
495 | |
496 | |
497 | |
498 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
499 <h2 heading><a name="lang">The Language</a></h2> |
380 | 500 |
501 <p> | |
502 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
|
503 In other words, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
504 this section describes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
505 which tokens are valid, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
506 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
|
507 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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
511 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
|
512 in which |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
513 {<em>a</em>} means 0 or more <em>a</em>'s, and |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
514 [<em>a</em>] means an optional <em>a</em>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
515 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
|
516 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
|
517 and other terminal symbols are shown like ‘<b>=</b>’. |
380 | 518 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
|
519 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
|
520 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
521 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
522 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
523 <h3 heading><a name="lex">Lexical Conventions</a></h3> |
380 | 524 |
525 <p> | |
526 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
|
527 between lexical elements (tokens), |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
528 except as delimiters between names and keywords. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
529 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 ( <em>(...)</em>, <em>[...]</em>, and <em>{...}</em> ) where the end of line is treated as white space. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
530 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
531 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
532 <em>Names</em> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
533 (also called <em>identifiers</em>) |
380 | 534 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
|
535 digits, and underscores, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
536 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
|
537 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
|
538 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
539 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
540 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
541 The following <em>keywords</em> are reserved |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
542 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
|
543 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
544 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
545 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
546 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
|
547 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
|
548 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
|
549 then true until while |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
550 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
551 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
552 <p> |
380 | 553 Luan is a case-sensitive language: |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
554 <code>and</code> is a reserved word, but <code>And</code> and <code>AND</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
555 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
|
556 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
557 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
558 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
559 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
|
560 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
561 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
562 + - * / % ^ # |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
563 & ~ | << >> // |
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 ( ) { } [ ] :: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
566 ; : , . .. ... |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
567 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
568 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
569 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
570 <em>Literal strings</em> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
571 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
|
572 and can contain the following C-like escape sequences: |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
573 '<code>\a</code>' (bell), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
574 '<code>\b</code>' (backspace), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
575 '<code>\f</code>' (form feed), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
576 '<code>\n</code>' (newline), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
577 '<code>\r</code>' (carriage return), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
578 '<code>\t</code>' (horizontal tab), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
579 '<code>\v</code>' (vertical tab), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
580 '<code>\\</code>' (backslash), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
581 '<code>\"</code>' (quotation mark [double quote]), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
582 and '<code>\'</code>' (apostrophe [single quote]). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
583 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
|
584 results in a newline in the string. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
585 The escape sequence '<code>\z</code>' 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
|
586 of white-space characters, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
587 including line breaks; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
588 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
|
589 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
|
590 into the string contents. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
591 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
592 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
593 <p> |
380 | 594 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
|
595 This can be done |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
596 with the escape sequence <code>\x<em>XX</em></code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
597 where <em>XX</em> is a sequence of exactly two hexadecimal digits, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
598 or with the escape sequence <code>\<em>ddd</em></code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
599 where <em>ddd</em> 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
|
600 (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
|
601 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
|
602 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
603 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
604 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
605 Literal strings can also be defined using a long format |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
606 enclosed by <em>long brackets</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
607 We define an <em>opening long bracket of level <em>n</em></em> as an opening |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
608 square bracket followed by <em>n</em> 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
|
609 opening square bracket. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
610 So, an opening long bracket of level 0 is written as <code>[[</code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
611 an opening long bracket of level 1 is written as <code>[=[</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
612 and so on. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
613 A <em>closing long bracket</em> is defined similarly; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
614 for instance, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
615 a closing long bracket of level 4 is written as <code>]====]</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
616 A <em>long literal</em> 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
|
617 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
|
618 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
|
619 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
|
620 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
|
621 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
|
622 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
|
623 (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
|
624 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
|
625 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
|
626 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
627 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
628 <p> |
380 | 629 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
|
630 explicitly affected by the previous rules represents itself. |
380 | 631 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
|
632 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
|
633 some control characters. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
634 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
|
635 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
|
636 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
|
637 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
638 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
639 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
640 For convenience, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
641 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
|
642 the newline is not included in the string. |
380 | 643 As an example |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
644 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
|
645 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
646 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
647 a = 'alo\n123"' |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
648 a = "alo\n123\"" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
649 a = '\97lo\10\04923"' |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
650 a = [[alo |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
651 123"]] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
652 a = [==[ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
653 alo |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
654 123"]==] |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
655 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
656 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
657 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
658 A <em>numerical constant</em> (or <em>numeral</em>) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
659 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
|
660 and an optional decimal exponent, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
661 marked by a letter '<code>e</code>' or '<code>E</code>'. |
380 | 662 Luan also accepts hexadecimal constants, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
663 which start with <code>0x</code> or <code>0X</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
664 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
|
665 plus an optional binary exponent, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
666 marked by a letter '<code>p</code>' or '<code>P</code>'. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
667 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
|
668 denotes a float; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
669 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
|
670 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
|
671 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
672 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
673 3 345 0xff 0xBEBADA |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
674 </pre> |
382 | 675 |
676 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
677 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
|
678 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
679 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
680 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
|
681 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
682 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
683 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
684 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
685 A <em>comment</em> starts with a double hyphen (<code>--</code>) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
686 anywhere outside a string. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
687 If the text immediately after <code>--</code> is not an opening long bracket, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
688 the comment is a <em>short comment</em>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
689 which runs until the end of the line. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
690 Otherwise, it is a <em>long comment</em>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
691 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
|
692 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
|
693 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
694 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
695 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
696 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
697 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
698 <h3 heading><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
|
699 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
700 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
701 Variables are places that store values. |
380 | 702 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
|
703 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
|
704 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
705 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
706 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
|
707 (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
|
708 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
|
709 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
710 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
711 var ::= Name |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
712 </pre> |
382 | 713 |
714 <p> | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
715 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
|
716 |
512
d96944467ffc
update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
505
diff
changeset
|
717 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
718 Local variables are <em>lexically scoped</em>: |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
719 local variables can be freely accessed by functions |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
720 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
|
721 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
722 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
723 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
724 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
|
725 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
726 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
727 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
|
728 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
729 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
730 var ::= prefixexp ‘<b>[</b>’ exp ‘<b>]</b>’ |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
731 </pre> |
382 | 732 |
733 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
734 The meaning of accesses to table fields can be changed via metatables. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
735 An access to an indexed variable <code>t[i]</code> is equivalent to |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
736 a call <code>gettable_event(t,i)</code>. |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
737 (See <a href="#meta">Metatables and Metamethods</a> for a complete description of the |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
738 <code>gettable_event</code> function. |
380 | 739 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
|
740 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
|
741 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
742 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
743 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
744 The syntax <code>var.Name</code> is just syntactic sugar for |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
745 <code>var["Name"]</code>: |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
746 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
747 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
748 var ::= prefixexp ‘<b>.</b>’ Name |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
749 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
750 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
751 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
752 Global variables are not available by default. To enable global variable, you must define <code>_ENV</code> as a local variable whose value is a table. If <code>_ENV</code> is not defined, then an unrecognized variable name will produce a compile error. If <code>_ENV</code> is defined then an access to an unrecognized variable name will be consider a global variable. So then an acces to global variable <code>x</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
753 is equivalent to <code>_ENV.x</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
754 Due to the way that chunks are compiled, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
755 <code>_ENV</code> is never a global name (see <a href="#env">Environments</a>). |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
756 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
757 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
758 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
759 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
760 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
761 <h3 heading><a name="stmts">Statements</a></h3> |
389 | 762 |
763 <p> | |
764 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
|
765 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
|
766 This set includes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
767 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
|
768 and variable declarations. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
769 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
770 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
771 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
772 <h4 heading><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
|
773 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
774 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
775 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
|
776 which are executed sequentially: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
777 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
778 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
779 block ::= {stat} |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
780 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
781 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
782 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
783 Luan has <em>empty statements</em> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
784 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
|
785 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
|
786 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
|
787 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
788 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
789 stat ::= ‘<b>;</b>’ |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
790 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
791 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
792 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
793 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
|
794 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
795 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
796 stat ::= <b>do</b> block <b>end</b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
797 </pre> |
389 | 798 |
799 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
800 Explicit blocks are useful |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
801 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
|
802 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
|
803 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
|
804 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
|
805 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
806 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
807 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
808 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
809 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
810 <h4 heading><a name="chunks">Chunks</a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
811 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
812 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
813 The unit of compilation of Luan is called a <em>chunk</em>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
814 Syntactically, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
815 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
|
816 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
817 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
818 chunk ::= block |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
819 </pre> |
395 | 820 |
821 <p> | |
822 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
|
823 with a variable number of arguments |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
824 (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
|
825 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
|
826 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
|
827 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
828 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
829 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
830 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
|
831 To execute a chunk, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
832 Luan first <em>loads</em> it, |
395 | 833 compiling the chunk's code, |
834 and then Luan executes the compiled code. | |
835 | |
836 | |
837 | |
838 | |
839 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
840 <h4 heading><a name="assignment">Assignment</a></h4> |
395 | 841 |
842 <p> | |
843 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
|
844 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
|
845 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
|
846 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
|
847 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
|
848 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
849 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
850 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
|
851 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
|
852 explist ::= exp {‘<b>,</b>’ exp} |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
853 </pre> |
395 | 854 |
855 <p> | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
856 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
|
857 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
858 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
859 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
860 Before the assignment, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
861 the list of values is <em>adjusted</em> 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
|
862 the list of variables. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
863 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
|
864 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
|
865 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
|
866 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
|
867 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
|
868 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
|
869 before the adjustment |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
870 (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
|
871 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
872 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
873 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
874 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
|
875 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
|
876 Thus the code |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
877 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
878 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
879 i = 3 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
880 i, a[i] = i+1, 20 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
881 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
882 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
883 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
884 sets <code>a[3]</code> to 20, without affecting <code>a[4]</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
885 because the <code>i</code> in <code>a[i]</code> 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
|
886 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
|
887 Similarly, the line |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
888 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
889 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
890 x, y = y, x |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
891 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
892 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
893 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
894 exchanges the values of <code>x</code> and <code>y</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
895 and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
896 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
897 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
898 x, y, z = y, z, x |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
899 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
900 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
901 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
902 cyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
903 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
904 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
905 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
906 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
|
907 and table fields can be changed via metatables. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
908 An assignment to an indexed variable <code>t[i] = val</code> is equivalent to |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
909 <code>settable_event(t,i,val)</code>. |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
910 (See <a href="#meta">Metatables and Metamethods</a> for a complete description of the |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
911 <code>settable_event</code> function. |
395 | 912 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
|
913 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
|
914 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
915 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
916 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
917 An assignment to a global name <code>x = val</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
918 is equivalent to the assignment |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
919 <code>_ENV.x = val</code> (see <a href="#env">Environments</a>). |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
920 Global names are only available when <code>_ENV</code> is defined. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
921 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
922 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
923 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
924 <h4 heading><a name="control">Control Structures</a></h4> |
395 | 925 |
926 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
927 The control structures |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
928 <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
|
929 familiar syntax: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
930 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
931 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
932 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
|
933 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
|
934 stat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
935 </pre> |
395 | 936 |
937 <p> | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
938 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
|
939 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
942 The condition expression of a |
395 | 943 control structure must be a boolean. |
944 Any other value type will produce an error. | |
945 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
|
946 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
947 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
948 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
949 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
|
950 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
|
951 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
|
952 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
|
953 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
|
954 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
955 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
956 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
957 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
|
958 <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
|
959 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
|
960 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
961 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
962 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
963 stat ::= <b>break</b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
964 </pre> |
395 | 965 |
966 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
967 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
|
968 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
969 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
970 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
971 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
|
972 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
|
973 (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
|
974 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
975 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
|
976 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
|
977 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
978 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
979 stat ::= <b>return</b> [explist] [‘<b>;</b>’] |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
980 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
981 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
982 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
983 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
984 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
985 <h4 heading><a name="for">For Statement</a></h4> |
395 | 986 |
987 <p> | |
988 The <b>for</b> statement works over functions, | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
989 called <em>iterators</em>. |
395 | 990 On each iteration, the iterator function is called to produce a new value, |
991 stopping when this new value is <b>nil</b>. | |
992 The <b>for</b> loop has the following syntax: | |
993 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
994 <pre> |
395 | 995 stat ::= <b>for</b> namelist <b>in</b> exp <b>do</b> block <b>end</b> |
996 namelist ::= Name {‘<b>,</b>’ Name} | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
997 </pre> |
395 | 998 |
999 <p> | |
1000 A <b>for</b> statement like | |
1001 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1002 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1003 for <em>var_1</em>, ···, <em>var_n</em> in <em>exp</em> do <em>block</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1004 </pre> |
395 | 1005 |
1006 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1007 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
|
1008 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1009 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1010 do |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1011 local <em>f</em> = <em>exp</em> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1012 while true do |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1013 local <em>var_1</em>, ···, <em>var_n</em> = <em>f</em>() |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1014 if <em>var_1</em> == nil then break end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1015 <em>block</em> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1016 end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1017 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1018 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1019 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1020 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1021 Note the following: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1022 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1023 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1024 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1025 <li> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1026 <code><em>exp</em></code> is evaluated only once. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1027 Its result is an <em>iterator</em> function. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1028 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1029 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1030 <li> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1031 <code><em>f</em></code> is an invisible variable. |
395 | 1032 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
|
1033 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1034 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1035 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1036 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
|
1037 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1038 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1039 <li> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1040 The loop variables <code><em>var_i</em></code> 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
|
1041 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
|
1042 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
|
1043 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
|
1044 </li> |
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 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1047 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1050 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1051 <h4 heading><a name="fn_stmt">Function Calls as Statements</a></h4> |
395 | 1052 |
1053 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1054 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
|
1055 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
|
1056 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1057 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1058 stat ::= functioncall |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1059 </pre> |
395 | 1060 |
1061 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1062 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
|
1063 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
|
1064 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1065 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1066 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1067 <h4 heading><a name="local_stmt">Local Declarations</a></h4> |
395 | 1068 |
1069 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1070 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
|
1071 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
|
1072 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1073 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1074 stat ::= <b>local</b> namelist [‘<b>=</b>’ explist] |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1075 </pre> |
395 | 1076 |
1077 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1078 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
|
1079 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
|
1080 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
|
1081 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1082 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1083 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1084 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
|
1085 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
|
1086 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1087 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1088 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1089 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
|
1090 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1091 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1092 <h4 heading><a name="template_stmt">Template Statements</a></h4> |
465 | 1093 |
1094 <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> | |
1095 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1096 <pre><%=Html.encode[[ |
465 | 1097 local name = "Bob" |
1098 %> | |
469 | 1099 Hello <%= name %>! |
1100 Bye <%= name %>. | |
465 | 1101 <% |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1102 ]]%></pre> |
465 | 1103 |
1104 <p>is equivalent to the code:</p> | |
1105 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1106 <pre><%=Html.encode[[ |
465 | 1107 local name = "Bob" |
1108 require("luan:Io").stdout.write( %> | |
469 | 1109 Hello <%= name %>! |
1110 Bye <%= name %>. | |
465 | 1111 <% ) |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1112 ]]%></pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1113 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1114 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1115 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1116 <h3 heading><a name="expressions">Expressions</a></h3> |
395 | 1117 |
1118 <p> | |
1119 The basic expressions in Luan are the following: | |
1120 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1121 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1122 exp ::= prefixexp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1123 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
|
1124 exp ::= Numeral |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1125 exp ::= LiteralString |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1126 exp ::= functiondef |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1127 exp ::= tableconstructor |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1128 exp ::= ‘<b>...</b>’ |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1129 exp ::= exp binop exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1130 exp ::= unop exp |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1131 prefixexp ::= var | functioncall | ‘<b>(</b>’ exp ‘<b>)</b>’ |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1132 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1133 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1134 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1135 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
|
1136 variables are explained in <a href="#vars">Variables</a>; |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1137 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
|
1138 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
|
1139 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
|
1140 Vararg expressions, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1141 denoted by three dots ('<code>...</code>'), 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
|
1142 directly inside a vararg function; |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1143 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
|
1144 |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1145 |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1146 <p> |
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1147 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
|
1148 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
|
1149 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
|
1150 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
|
1151 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
|
1152 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
|
1153 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1154 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1155 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1156 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
|
1157 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
|
1158 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
|
1159 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
|
1160 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
|
1161 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
|
1162 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
|
1163 (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
|
1164 In all other contexts, |
395 | 1165 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
|
1166 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
|
1167 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
|
1168 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1169 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1170 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1171 Here are some examples: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1172 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1173 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1174 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
|
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 -- 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
|
1180 -- 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
|
1181 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1182 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
|
1183 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
|
1184 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
|
1185 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
|
1186 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
|
1187 {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
|
1188 {...} -- 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
|
1189 {f(), nil} -- f() is adjusted to 1 result |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1190 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1191 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1192 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1193 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
|
1194 Thus, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1195 <code>(f(x,y,z))</code> is always a single value, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1196 even if <code>f</code> returns several values. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1197 (The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1198 or <b>nil</b> if <code>f</code> does not return any values.) |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1199 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1200 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1201 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1202 <h4 heading><a name="arithmetic">Arithmetic Operators</a></h4> |
395 | 1203 |
1204 <p> | |
1205 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
|
1206 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1207 <ul> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1208 <li><b><code>+</code>: </b>addition</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1209 <li><b><code>-</code>: </b>subtraction</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1210 <li><b><code>*</code>: </b>multiplication</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1211 <li><b><code>/</code>: </b>division</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1212 <li><b><code>%</code>: </b>modulo</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1213 <li><b><code>^</code>: </b>exponentiation</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1214 <li><b><code>-</code>: </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
|
1215 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1216 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1217 <p> |
395 | 1218 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
|
1219 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1220 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1221 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
|
1222 that rounds the quotient towards minus infinite (floor division). |
395 | 1223 (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
|
1224 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1225 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1226 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1227 <h4 heading><a name="conversions">Coercions and Conversions</a></h4> |
396 | 1228 |
1229 <p> | |
465 | 1230 Luan generally avoids automatic conversions. |
1231 String concatenation automatically converts all of its arguments to strings. | |
1232 | |
1233 <p> | |
1234 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
|
1235 |
396 | 1236 |
1237 | |
1238 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1239 <h4 heading><a name="relational">Relational Operators</a></h4> |
396 | 1240 |
1241 <p> | |
1242 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
|
1243 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1244 <ul> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1245 <li><b><code>==</code>: </b>equality</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1246 <li><b><code>~=</code>: </b>inequality</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1247 <li><b><code><</code>: </b>less than</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1248 <li><b><code>></code>: </b>greater than</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1249 <li><b><code><=</code>: </b>less or equal</li> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1250 <li><b><code>>=</code>: </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
|
1251 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1252 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
|
1253 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1254 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1255 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1256 Equality (<code>==</code>) 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
|
1257 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
|
1258 Otherwise, the values of the operands are compared. |
396 | 1259 Strings, numbers, and binary values are compared in the obvious way (by value). |
1260 | |
1261 <p> | |
1262 Tables | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1263 are compared by reference: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1264 two objects are considered equal only if they are the same object. |
396 | 1265 Every time you create a new table, |
1266 it is different from any previously existing table. | |
1267 Closures are also compared by reference. | |
1268 | |
1269 <p> | |
417 | 1270 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
|
1271 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
|
1272 |
396 | 1273 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1274 Java values 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)"><code>equals</code></a> method. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1275 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1276 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1277 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
|
1278 or vice versa. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1279 Thus, <code>"0"==0</code> evaluates to <b>false</b>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1280 and <code>t[0]</code> and <code>t["0"]</code> denote different |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1281 entries in a table. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1282 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1283 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1284 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1285 The operator <code>~=</code> is exactly the negation of equality (<code>==</code>). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1286 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1287 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1288 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1289 The order operators work as follows. |
396 | 1290 |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1291 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
|
1292 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
|
1293 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
|
1294 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
|
1295 then their values are compared according to the current locale. |
396 | 1296 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
|
1297 metamethod (see <a href="#meta">Metatables and Metamethods</a>). |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1298 A comparison <code>a > b</code> is translated to <code>b < a</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1299 and <code>a >= b</code> is translated to <code>b <= a</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1300 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1301 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1302 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1303 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1304 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1305 <h4 heading><a name="logical_ops">Logical Operators</a></h4> |
396 | 1306 |
1307 <p> | |
1308 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
|
1309 <b>and</b>, <b>or</b>, and <b>not</b>. |
396 | 1310 The <b>and</b> and <b>or</b> operators consider both <b>false</b> and <b>nil</b> as false |
1311 and anything else as true. | |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1312 Like the control structures (see <a href="#control">Control Structures</a>), |
396 | 1313 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
|
1314 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1315 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 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
|
1322 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
|
1323 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
|
1324 that is, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1325 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
|
1326 Here are some examples: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1327 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1328 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1329 10 or 20 --> 10 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1330 10 or error() --> 10 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1331 nil or "a" --> "a" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1332 nil and 10 --> nil |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1333 false and error() --> false |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1334 false and nil --> false |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1335 false or nil --> nil |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1336 10 and 20 --> 20 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1337 </pre> |
396 | 1338 |
1339 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1340 (In this manual, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1341 <code>--></code> indicates the result of the preceding expression.) |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1342 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1343 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1344 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1345 <h4 heading><a name="concatenation">Concatenation</a></h4> |
396 | 1346 |
1347 <p> | |
1348 The string concatenation operator in Luan is | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1349 denoted by two dots ('<code>..</code>'). |
396 | 1350 All operands are converted to strings. |
1351 | |
1352 | |
1353 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1354 <h4 heading><a name="length">The Length Operator</a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1355 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1356 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1357 The length operator is denoted by the unary prefix operator <code>#</code>. |
396 | 1358 The length of a string is its number of characters. |
1359 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
|
1360 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1361 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1362 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1363 A program can modify the behavior of the length operator for |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1364 any table through the <code>__len</code> metamethod (see <a href="#meta">Metatables and Metamethods</a>). |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1365 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1366 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1367 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1368 Unless a <code>__len</code> metamethod is given, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1369 the length of a table <code>t</code> is defined |
396 | 1370 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
|
1371 that is, |
396 | 1372 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
|
1373 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
|
1374 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
|
1375 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
|
1376 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1377 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1378 {10, 20, nil, 40} |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1379 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1380 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1381 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1382 has a length of <code>2</code>, because that is the last key in sequence. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1383 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1384 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1385 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1386 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1387 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1388 <h4 heading><a name="precedence">Precedence</a></h4> |
396 | 1389 |
1390 <p> | |
1391 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
|
1392 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
|
1393 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1394 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1395 or |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1396 and |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1397 < > <= >= ~= == |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1398 .. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1399 + - |
396 | 1400 * / % |
1401 unary operators (not # -) | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1402 ^ |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1403 </pre> |
396 | 1404 |
1405 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1406 As usual, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1407 you can use parentheses to change the precedences of an expression. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1408 The concatenation ('<code>..</code>') and exponentiation ('<code>^</code>') |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1409 operators are right associative. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1410 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
|
1411 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1412 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1413 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1414 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1415 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1416 <h4 heading><a name="constructors">Table Constructors</a></h4> |
396 | 1417 |
1418 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1419 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
|
1420 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
|
1421 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
|
1422 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
|
1423 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
|
1424 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1425 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1426 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
|
1427 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
|
1428 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
|
1429 fieldsep ::= ‘<b>,</b>’ | ‘<b>;</b>’ |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1430 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1431 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1432 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1433 Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1434 with key <code>exp1</code> and value <code>exp2</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1435 A field of the form <code>name = exp</code> is equivalent to |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1436 <code>["name"] = exp</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1437 Finally, fields of the form <code>exp</code> are equivalent to |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1438 <code>[i] = exp</code>, where <code>i</code> are consecutive integers |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1439 starting with 1. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1440 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
|
1441 For example, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1442 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1443 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1444 a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1445 </pre> |
396 | 1446 |
1447 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1448 is equivalent to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1449 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1450 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1451 do |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1452 local t = {} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1453 t[f(1)] = g |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1454 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
|
1455 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
|
1456 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
|
1457 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
|
1458 t[30] = 23 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1459 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
|
1460 a = t |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1461 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1462 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1463 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1464 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1465 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
|
1466 (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
|
1467 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1468 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1469 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1470 If the last field in the list has the form <code>exp</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1471 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
|
1472 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
|
1473 (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
|
1474 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1475 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1476 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1477 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
|
1478 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
|
1479 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1480 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1481 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1482 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1483 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1484 <h4 heading><a name="fn_calls">Function Calls</a></h4> |
417 | 1485 |
1486 <p> | |
1487 A function call in Luan has the following syntax: | |
1488 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1489 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1490 functioncall ::= prefixexp args |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1491 </pre> |
417 | 1492 |
1493 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1494 In a function call, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1495 first prefixexp and args are evaluated. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1496 If the value of prefixexp has type <em>function</em>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1497 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
|
1498 with the given arguments. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1499 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
|
1500 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
|
1501 followed by the original call arguments |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1502 (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
|
1503 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1504 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1505 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1506 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
|
1507 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1508 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1509 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
|
1510 args ::= tableconstructor |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1511 args ::= LiteralString |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1512 </pre> |
417 | 1513 |
1514 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1515 All argument expressions are evaluated before the call. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1516 A call of the form <code>f{<em>fields</em>}</code> is |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1517 syntactic sugar for <code>f({<em>fields</em>})</code>; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1518 that is, the argument list is a single new table. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1519 A call of the form <code>f'<em>string</em>'</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1520 (or <code>f"<em>string</em>"</code> or <code>f[[<em>string</em>]]</code>) |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1521 is syntactic sugar for <code>f('<em>string</em>')</code>; |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1522 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
|
1523 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1524 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1525 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1526 A call of the form <code>return <em>functioncall</em></code> is called |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1527 a <em>tail call</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1528 Luan implements <em>proper tail calls</em> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1529 (or <em>proper tail recursion</em>): |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1530 in a tail call, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1531 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
|
1532 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
|
1533 a program can execute. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1534 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
|
1535 calling function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1536 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
|
1537 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
|
1538 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
|
1539 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
|
1540 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
|
1541 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1542 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1543 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
|
1544 return 2 * f(x) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1545 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
|
1546 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
|
1547 return x or f(x) -- results adjusted to 1 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1548 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1549 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1550 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1551 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1552 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1553 <h4 heading><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
|
1554 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1555 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1556 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
|
1557 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1558 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1559 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
|
1560 funcbody ::= ‘<b>(</b>’ [parlist] ‘<b>)</b>’ block <b>end</b> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1561 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1562 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1563 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1564 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
|
1565 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1566 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1567 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
|
1568 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
|
1569 funcname ::= Name {‘<b>.</b>’ Name} [‘<b>:</b>’ Name] |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1570 </pre> |
417 | 1571 |
1572 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1573 The statement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1574 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1575 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1576 function f () <em>body</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1577 </pre> |
417 | 1578 |
1579 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1580 translates to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1581 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1582 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1583 f = function () <em>body</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1584 </pre> |
417 | 1585 |
1586 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1587 The statement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1588 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1589 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1590 function t.a.b.c.f () <em>body</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1591 </pre> |
417 | 1592 |
1593 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1594 translates to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1595 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1596 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1597 t.a.b.c.f = function () <em>body</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1598 </pre> |
417 | 1599 |
1600 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1601 The statement |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1602 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1603 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1604 local function f () <em>body</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1605 </pre> |
417 | 1606 |
1607 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1608 translates to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1609 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1610 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1611 local f; f = function () <em>body</em> end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1612 </pre> |
417 | 1613 |
1614 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1615 not to |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1616 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1617 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1618 local f = function () <em>body</em> end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1619 </pre> |
417 | 1620 |
1621 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1622 (This only makes a difference when the body of the function |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1623 contains references to <code>f</code>.) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1624 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1625 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1626 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1627 A function definition is an executable expression, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1628 whose value has type <em>function</em>. |
417 | 1629 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
|
1630 all its function bodies are precompiled too. |
417 | 1631 Then, whenever Luan executes the function definition, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1632 the function is <em>instantiated</em> (or <em>closed</em>). |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1633 This function instance (or <em>closure</em>) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1634 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
|
1635 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1636 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1637 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1638 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
|
1639 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
|
1640 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1641 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1642 parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’ |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1643 </pre> |
417 | 1644 |
1645 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1646 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
|
1647 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
|
1648 the length of the list of parameters, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1649 unless the function is a <em>vararg function</em>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1650 which is indicated by three dots ('<code>...</code>') |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1651 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
|
1652 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
|
1653 instead, it collects all extra arguments and supplies them |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1654 to the function through a <em>vararg expression</em>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1655 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
|
1656 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
|
1657 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
|
1658 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
|
1659 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
|
1660 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
|
1661 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
|
1662 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
|
1663 (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
|
1664 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1665 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1666 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1667 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
|
1668 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1669 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1670 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
|
1671 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
|
1672 function r() return 1,2,3 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1673 </pre> |
417 | 1674 |
1675 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1676 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
|
1677 to the vararg expression: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1678 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1679 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1680 CALL PARAMETERS |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1681 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1682 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
|
1683 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
|
1684 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
|
1685 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
|
1686 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
|
1687 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1688 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
|
1689 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
|
1690 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
|
1691 g(5, r()) a=5, b=1, ... --> 2 3 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1692 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1693 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1694 <p> |
464
eddf7c73373b
fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
429
diff
changeset
|
1695 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
|
1696 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
|
1697 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
|
1698 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
|
1699 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1700 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1701 <h4 heading><a name="template_expr">Template Expressions</a></h4> |
465 | 1702 |
1703 <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> | |
1704 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1705 <pre><%=Html.encode[[ |
465 | 1706 local name = "Bob" |
469 | 1707 write( %>Hello <%= name %>!<% ) |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1708 ]]%></pre> |
465 | 1709 |
1710 <p>This is equivalent to the code:</p> | |
1711 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1712 <pre> |
465 | 1713 local name = "Bob" |
1714 write( "Hello ", name, "!" ) | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1715 </pre> |
465 | 1716 |
1717 <p>The strings in template expressions may be multiple lines.</p> | |
1718 | |
417 | 1719 |
1720 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1721 <h3 heading><a name="visibility">Visibility Rules</a></h3> |
417 | 1722 |
1723 <p> | |
1724 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
|
1725 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
|
1726 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
|
1727 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
|
1728 Consider the following example: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1729 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1730 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1731 x = 10 -- global variable |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1732 do -- new block |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1733 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
|
1734 print(x) --> 10 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1735 x = x+1 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1736 do -- another block |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1737 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
|
1738 print(x) --> 12 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1739 end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1740 print(x) --> 11 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1741 end |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1742 print(x) --> 10 (the global one) |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1743 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1744 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1745 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1746 Notice that, in a declaration like <code>local x = x</code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1747 the new <code>x</code> being declared is not in scope yet, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1748 and so the second <code>x</code> 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
|
1749 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1750 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1751 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1752 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
|
1753 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
|
1754 defined inside their scope. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1755 A local variable used by an inner function is called |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1756 an <em>upvalue</em>, or <em>external local variable</em>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1757 inside the inner function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1758 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1759 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1760 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1761 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
|
1762 defines new local variables. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1763 Consider the following example: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1764 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1765 <pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1766 a = {} |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1767 local x = 20 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1768 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
|
1769 local y = 0 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1770 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
|
1771 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1772 </pre> |
417 | 1773 |
1774 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1775 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
|
1776 (that is, ten instances of the anonymous function). |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1777 Each of these closures uses a different <code>y</code> variable, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1778 while all of them share the same <code>x</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1779 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1780 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1781 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1782 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1783 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1784 <h2 heading><a name="libs">Standard Libraries</a></h2> |
468 | 1785 |
1786 <p> | |
1787 The standard Luan libraries provide useful functions | |
1788 that are implemented both in Java and in Luan itself. | |
1789 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
|
1790 Some of these functions provide essential services to the language |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1791 (e.g., <a href="#Luan.type"><code>type</code></a> and <a href="#Luan.get_metatable"><code>get_metatable</code></a>); |
468 | 1792 others provide access to "outside" services (e.g., I/O). |
1793 | |
1794 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1795 <h3 heading><a name="default_lib">Default Environment</a></h3> |
468 | 1796 |
1797 <p> | |
1798 These are provided by default as local variables for any Luan code as described in <a href="#env">Environments</a>. | |
1799 | |
470 | 1800 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1801 <h4 heading><a name="require"><code>java ()</code></a></h4> |
470 | 1802 |
1803 <p> | |
1804 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. | |
1805 | |
1806 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1807 <h4 heading><a name="require"><code>require (mod_uri)</code></a></h4> |
470 | 1808 |
1809 <p> | |
1810 Example use: | |
1811 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1812 <pre> |
470 | 1813 local Table = require "luan:Table" |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1814 </pre> |
470 | 1815 |
1816 <p> | |
1817 Could be defined as: | |
1818 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1819 <pre> |
470 | 1820 local function require(mod_name) |
476 | 1821 return <a href="#Package.load">Package.load</a>(mod_name) or <a href="#Luan.error">Luan.error</a>("module '"..mod_name.."' not found") |
470 | 1822 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1823 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1824 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1825 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1826 <h3 heading><a name="luan_lib">Basic Functions</a></h3> |
470 | 1827 |
1828 <p> | |
1829 Include this library by: | |
1830 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1831 <pre> |
470 | 1832 local Luan = require "luan:Luan" |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1833 </pre> |
470 | 1834 |
476 | 1835 <p> |
470 | 1836 The basic library provides basic functions to Luan that don't depend on other libaries. |
1837 | |
1838 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1839 <h4 heading><a name="Luan.assert"><code>Luan.assert (v [, message])</code></a></h4> |
470 | 1840 |
1841 <p> | |
1842 Could be defined as: | |
1843 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1844 <pre> |
470 | 1845 function Luan.assert(v,message) |
472 | 1846 return v or <a href="#Luan.error">Luan.error</a>(message or "assertion failed!") |
470 | 1847 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1848 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1849 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1850 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1851 <h4 heading><a name="Luan.assert_binary"><code>Luan.assert_binary (v)</code></a></h4> |
470 | 1852 |
1853 <p> | |
1854 Could be defined as: | |
1855 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1856 <pre> |
470 | 1857 function Luan.assert_binary(v) |
1858 local v_type = Luan.type(v) | |
472 | 1859 return v_type == "binary" and v or <a href="#Luan.error">Luan.error</a>("bad argument #1 (binary expected, got "..v_type..")") |
470 | 1860 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1861 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1862 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1863 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1864 <h4 heading><a name="Luan.assert_boolean"><code>Luan.assert_boolean (v)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1865 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1866 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1867 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>boolean</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1868 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1869 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1870 <h4 heading><a name="Luan.assert_integer"><code>Luan.assert_integer (v)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1871 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1872 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1873 Asserts that <code>v</code> 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. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1874 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1875 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1876 <h4 heading><a name="Luan.assert_long"><code>Luan.assert_long (v)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1877 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1878 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1879 Asserts that <code>v</code> 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. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1880 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1881 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1882 <h4 heading><a name="Luan.assert_number"><code>Luan.assert_number (v)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1883 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1884 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1885 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>number</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1886 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1887 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1888 <h4 heading><a name="Luan.assert_string"><code>Luan.assert_string (v)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1889 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1890 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1891 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>string</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1892 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1893 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1894 <h4 heading><a name="Luan.assert_table"><code>Luan.assert_table (v)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1895 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1896 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1897 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>table</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1898 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1899 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1900 <h4 heading><a name="Luan.do_file"><code>Luan.do_file ([uri])</code></a></h4> |
470 | 1901 |
1902 <p> | |
1903 Could be defined as: | |
1904 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1905 <pre> |
470 | 1906 function Luan.do_file(uri) |
474 | 1907 return <a href="#Luan.load_file">Luan.load_file</a>(uri)() |
470 | 1908 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1909 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1910 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1911 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1912 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1913 <h4 heading><a name="Luan.error"><code>Luan.error (message)</code></a></h4> |
470 | 1914 |
1915 <p> | |
482 | 1916 Throws an error containing the message. |
1917 | |
1918 <p> | |
1919 Could be defined as: | |
1920 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1921 <pre> |
482 | 1922 function Luan.error(message) |
1923 <a href="#Luan.new_error">Luan.new_error</a>(message).throw() | |
1924 end | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1925 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1926 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1927 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1928 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1929 <h4 heading><a name="Luan.get_metatable"><code>Luan.get_metatable (table)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1930 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1931 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1932 If <code>table</code> 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
|
1933 Otherwise, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1934 if the table's metatable has a <code>"__metatable"</code> field, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1935 returns the associated value. |
470 | 1936 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
|
1937 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1938 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1939 <h4 heading><a name="Luan.ipairs"><code>Luan.ipairs (t)</code></a></h4> |
474 | 1940 |
1941 <p> | |
1942 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
|
1943 so that the construction |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1944 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1945 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1946 for i,v in ipairs(t) do <em>body</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1947 </pre> |
474 | 1948 |
1949 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1950 will iterate over the key–value pairs |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1951 (<code>1,t[1]</code>), (<code>2,t[2]</code>), ..., |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1952 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
|
1953 |
474 | 1954 <p> |
1955 Could be defined as: | |
1956 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1957 <pre> |
474 | 1958 function Luan.ipairs(t) |
1959 local i = 0 | |
1960 return function() | |
1961 if i < #t then | |
1962 i = i + 1 | |
1963 return i, t[i] | |
1964 end | |
1965 end | |
1966 end | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1967 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1968 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1969 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1970 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1971 <h4 heading><a name="Luan.load"><code>Luan.load (text, source_name [env, [, allow_expression]])</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1972 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1973 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1974 Loads a chunk. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1975 |
474 | 1976 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1977 The <code>text</code> is compiled. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1978 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
|
1979 returns the compiled chunk as a function; |
474 | 1980 otherwise, throws an error. |
1981 | |
1982 <p> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1983 The <code>source_name</code> parameter is a string saying where the text came from. It is used to produce error messages. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1984 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1985 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1986 If the <code>env</code> parameter is supplied, it becomes the <code>_ENV</code> of the chunk. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1987 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1988 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1989 If the <code>allow_expression</code> parameter is <code>true</code> then the entire text can be nothing more than an expression in which case the chunk returns the value of this expression. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1990 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1991 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1992 <h4 heading><a name="Luan.load_file"><code>Luan.load_file (file_uri [, add_extension])</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1993 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1994 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1995 Similar to <a href="#Luan.load"><code>load</code></a>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
1996 but gets the chunk from file <code>file_uri</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1997 or from the standard input, |
474 | 1998 if no file uri is given. |
1999 | |
2000 <p> | |
2001 Could be defined as: | |
2002 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2003 <pre> |
474 | 2004 function Luan.load_file(file_uri,add_extension) |
2005 file_uri = file_uri or "stdin:" | |
2006 local f = Io.uri(file_uri,add_extension) | |
2007 f.exists() or <a href="#Luan.error">Luan.error</a>("file '"..file_uri.."' not found") | |
2008 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri ) | |
2009 end | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2010 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2011 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2012 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2013 <h4 heading><a name="Luan.new_error"><code>Luan.new_error (message)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2014 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2015 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2016 Creates a new error table containing the message assigned to "<code>message</code>". The error table also contains a <code>throw</code> function which throws the error. The table also contains a list of stack trace elements where each stack trace element is a table containing "<code>source</code>", "<code>line</code>", and possible "<code>call_to</code>". The table also has a metatable containing "<code>__to_string</code>" to render the error. |
482 | 2017 |
2018 <p> | |
2019 To print the current stack trace, you could do: | |
2020 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2021 <pre> |
482 | 2022 Io.print( Luan.new_error "stack" ) |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2023 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2024 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2025 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2026 <h4 heading><a name="Luan.pairs"><code>Luan.pairs (t)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2027 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2028 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2029 If <code>t</code> has a metamethod <code>__pairs</code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2030 calls it with <code>t</code> as argument and returns the |
475 | 2031 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
|
2032 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2033 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2034 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2035 Otherwise, |
475 | 2036 returns a function |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2037 so that the construction |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2038 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2039 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2040 for k,v in pairs(t) do <em>body</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2041 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2042 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2043 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2044 will iterate over all key–value pairs of table <code>t</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2045 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2046 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2047 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2048 <h4 heading><a name="Luan.pcall"><code>Luan.pcall (f [, arg1, ···])</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2049 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2050 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2051 Calls function <code>f</code> with |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2052 the given arguments in <em>protected mode</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2053 This means that any error inside <code>f</code> is not propagated; |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2054 instead, <code>pcall</code> catches the error |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2055 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
|
2056 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
|
2057 which is true if the call succeeds without errors. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2058 In such case, <code>pcall</code> 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
|
2059 after this first result. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2060 In case of any error, <code>pcall</code> 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
|
2061 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2062 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2063 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2066 <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
|
2067 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
|
2068 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
|
2069 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
|
2070 <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
|
2071 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
|
2072 for instance for debugging. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2073 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
|
2074 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
|
2075 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2076 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2077 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2078 <h4 heading><a name="Luan.range"><code>Luan.range (start, stop [, step])</code></a></h4> |
476 | 2079 |
2080 <p> | |
2081 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. | |
2082 | |
2083 <p> | |
2084 Example use: | |
2085 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2086 <pre> |
476 | 2087 for i in range(1,10) do |
2088 Io.print("count up:",i) | |
2089 end | |
2090 for i in range(10,0,-1) do | |
2091 Io.print("count down:",i) | |
2092 end | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2093 </pre> |
476 | 2094 |
2095 <p> | |
2096 Could be defined as: | |
2097 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2098 <pre> |
476 | 2099 function Luan.range(start, stop, step) |
2100 step = step or 1 | |
478 | 2101 step == 0 and <a href="#Luan.error">Luan.error</a> "bad argument #3 (step may not be zero)" |
476 | 2102 local i = start |
2103 return function() | |
2104 if step > 0 and i <= stop or step < 0 and i >= stop then | |
2105 local rtn = i | |
2106 i = i + step | |
2107 return rtn | |
2108 end | |
2109 end | |
2110 end | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2111 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2112 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2113 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2114 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2115 <h4 heading><a name="Luan.raw_equal"><code>Luan.raw_equal (v1, v2)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2116 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2117 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2118 Checks whether <code>v1</code> is equal to <code>v2</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2119 without invoking any metamethod. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2120 Returns a boolean. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2121 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2122 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2123 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2124 <h4 heading><a name="Luan.raw_get"><code>Luan.raw_get (table, index)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2125 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2126 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2127 Gets the real value of <code>table[index]</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2128 without invoking any metamethod. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2129 <code>table</code> must be a table; |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2130 <code>index</code> may be any value. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2131 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2132 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2133 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2134 <h4 heading><a name="Luan.raw_len"><code>Luan.raw_len (v)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2135 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2136 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2137 Returns the length of the object <code>v</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2138 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
|
2139 without invoking any metamethod. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2140 Returns an integer. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2141 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2142 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2143 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2144 <h4 heading><a name="Luan.raw_set"><code>Luan.raw_set (table, index, value)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2145 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2146 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2147 Sets the real value of <code>table[index]</code> to <code>value</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2148 without invoking any metamethod. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2149 <code>table</code> must be a table, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2150 <code>index</code> any value different from <b>nil</b>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2151 and <code>value</code> any Lua value. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2152 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2153 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2154 <h4 heading><a name="Luan.set_metatable"><code>Luan.set_metatable (table, metatable)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2155 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2156 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2157 Sets the metatable for the given table. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2158 If <code>metatable</code> 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
|
2159 removes the metatable of the given table. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2160 If the original metatable has a <code>"__metatable"</code> field, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2161 raises an error. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2162 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2163 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2164 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2165 <h4 heading><a name="Luan.to_string"><code>Luan.to_string (v)</code></a></h4> |
475 | 2166 |
2167 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2168 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
|
2169 converts it to a string in a human-readable format. |
475 | 2170 |
2171 <p> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2172 If the metatable of <code>v</code> has a <code>"__to_string"</code> field, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2173 then <code>to_string</code> calls the corresponding value |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2174 with <code>v</code> as argument, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2175 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
|
2176 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2177 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2178 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2179 <h4 heading><a name="Luan.try"><code>Luan.try (t)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2180 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2181 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2182 Implements try-catch as found in other languages where each block is in table <code>t</code>. <code>t[1]</code> is the "try" block. The <code>t.catch</code> and <code>t.finally</code> blocks are optional. Returns the result of the "try" block or the "catch" block. |
476 | 2183 |
2184 <p> | |
2185 Example use: | |
2186 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2187 <pre> |
476 | 2188 try { |
2189 function() | |
2190 a_dangerous_fn() | |
2191 end; | |
2192 catch = function(e) | |
2193 -- handle error | |
2194 end; | |
2195 finally = function() | |
2196 -- clean up | |
2197 end; | |
2198 } | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2199 </pre> |
476 | 2200 |
482 | 2201 <p> |
2202 Could be defined as: | |
2203 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2204 <pre> |
482 | 2205 function Luan.try(t) |
2206 local r = { <a href="#Luan.pcall">Luan.pcall</a>(t[1]) } | |
2207 if r[1] then | |
2208 Table.remove(r,1) | |
2209 elseif t.catch ~= nil then | |
2210 r = { t.catch(r[2]) } | |
2211 else | |
2212 t.finally and t.finally() | |
2213 r[2].throw() | |
2214 end | |
2215 t.finally and t.finally() | |
2216 return Table.unpack(r) | |
2217 end | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2218 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2219 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2220 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2221 <h4 heading><a name="Luan.type"><code>Luan.type (v)</code></a></h4> |
475 | 2222 |
2223 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2224 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
|
2225 The possible results of this function are |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2226 "<code>nil</code>" (a string, not the value <b>nil</b>), |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2227 "<code>number</code>", |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2228 "<code>string</code>", |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2229 "<code>binary</code>", |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2230 "<code>boolean</code>", |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2231 "<code>table</code>", |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2232 "<code>function</code>", |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2233 and "<code>java</code>". |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2234 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2235 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2236 <h4 heading><a name="Luan.values"><code>Luan.values (···)</code></a></h4> |
476 | 2237 |
2238 <p> | |
2239 Returns a function so that the construction | |
2240 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2241 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2242 for v in Luan.values(···) do <em>body</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2243 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2244 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2245 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2246 will iterate over all values of <code>···</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2247 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2248 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2249 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2250 <h4 heading><a name="Luan.VERSION"><code>Luan.VERSION</code></a></h4> |
475 | 2251 |
2252 <p> | |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2253 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
|
2254 holds a string containing the current interpreter version. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2255 The current value of this variable is "<code><%=Luan.VERSION%></code>". |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2256 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2257 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2258 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2259 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2260 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2261 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2262 <h3 heading><a name="package_lib">Modules</a></h3> |
476 | 2263 |
2264 <p> | |
2265 Include this library by: | |
2266 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2267 <pre> |
476 | 2268 local Package = require "luan:Package" |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2269 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2270 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2271 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2272 The package library provides basic |
476 | 2273 facilities for loading modules in Luan. |
2274 | |
2275 | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2276 <h4 heading><a name="Package.load"><code>Package.load (mod_uri)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2277 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2278 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2279 Loads the given module. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2280 The function starts by looking into the <a href="#Package.loaded"><code>Package.loaded</code></a> table |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2281 to determine whether <code>mod_uri</code> is already loaded. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2282 If it is, then <code>Package.load</code> returns the value stored |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2283 at <code>Package.loaded[mod_uri]</code>. |
476 | 2284 Otherwise, it tries to load a new value for the module. |
2285 | |
2286 <p> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2287 To load a new value, <code>Package.load</code> first checks if <code>mod_uri</code> starts with "<b>java:</b>". If yes, then this is a Java class which is loaded by special Java code. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2288 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2289 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2290 If <code>mod_uri</code> is not a Java class, then <code>Package.load</code> tries to read the text of the file referred to by <code>mod_uri</code> (using <code>add_extension</code>=true). If the file doesn't exist, then <code>Package.load</code> returns <b>nil</b>. If the file exists, then its content is compiled into a chunk calling <a href="#Luan.load"><code>Luan.load</code></a> and passing in an empty table as the <code>env</code> value. This chunk is run passing in <code>mod_uri</code> 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 <code>env</code> that was passed in is the value of this module. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2291 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2292 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2293 If a new value for the module successful loaded, then it is stored in <code>Package.loaded[mod_uri]</code>. The value is returned. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2294 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2295 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2296 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2297 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2298 <h4 heading><a name="Package.loaded"><code>Package.loaded</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2299 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2300 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2301 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2302 A table used by <a href="#Package.load"><code>Package.load</code></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
|
2303 modules are already loaded. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2304 When you load a module <code>mod_uri</code> and |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2305 <code>Package.loaded[mod_uri]</code> is not <b>nil</b>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2306 <a href="#Package.load"><code>Package.load</code></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
|
2307 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2308 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2309 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2310 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
|
2311 assignments to this variable do not change the |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2312 table used by <a href="#Package.load"><code>Package.load</code></a>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2313 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2314 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2315 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2316 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2317 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2318 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2319 <h3 heading><a name="string_lib">String Manipulation</a></h3> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2320 |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2321 <p> |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2322 Include this library by: |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2323 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2324 <pre> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2325 local String = require "luan:String" |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2326 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2327 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2328 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2329 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
|
2330 such as finding and extracting substrings, and pattern matching. |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2331 When indexing a string in Luan, the first character is at position 1 |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2332 (not at 0, as in Java). |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2333 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
|
2334 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
|
2335 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
|
2336 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2337 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2338 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2339 <h4 heading><a name="String.char"><code>String.char (···)</code></a></h4> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2340 |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2341 <p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2342 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
|
2343 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
|
2344 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
|
2345 to its corresponding argument. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2346 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2347 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2348 <h4 heading><a name="String.concat"><code>String.concat (···)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2349 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2350 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2351 Concatenates the <a href="#Luan.to_string"><code>to_string</code></a> value of all arguments. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2352 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2353 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2354 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2355 <h4 heading><a name="String.encode"><code>String.encode (s)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2356 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2357 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2358 Encodes argument <code>s</code> into a string that can be placed in quotes so as to return the original value of the string. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2359 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2360 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2361 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2362 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2363 <h4 heading><a name="String.find"><code>String.find (s, pattern [, init [, plain]])</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2364 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2365 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2366 Looks for the first match of |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2367 <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) in the string <code>s</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2368 If it finds a match, then <code>find</code> returns the indices of <code>s</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2369 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
|
2370 otherwise, it returns <b>nil</b>. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2371 A third, optional numerical argument <code>init</code> specifies |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2372 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
|
2373 its default value is 1 and can be negative. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2374 A value of <b>true</b> as a fourth, optional argument <code>plain</code> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2375 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
|
2376 so the function does a plain "find substring" operation, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2377 with no characters in <code>pattern</code> being considered magic. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2378 Note that if <code>plain</code> is given, then <code>init</code> must be given as well. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2379 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2380 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2381 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
|
2382 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
|
2383 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
|
2384 after the two indices. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2385 |
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 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2389 <h4 heading><a name="String.format"><code>String.format (formatstring, ···)</code></a></h4> |
371
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2393 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
|
2394 following the description given in its first argument (which must be a string). |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2395 The format string follows the same rules as the Java function <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object...)"><code>String.format</code></a> because Luan calls this internally. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2396 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2397 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2398 Note that Java's <code>String.format</code> is too stupid to convert between ints and floats, so you must provide the right kind of number. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2399 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2400 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2401 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2402 <h4 heading><a name="String.gmatch"><code>String.gmatch (s, pattern)</code></a></h4> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2403 |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2404 <p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2405 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
|
2406 each time it is called, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2407 returns the next captures from <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2408 over the string <code>s</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2409 If <code>pattern</code> specifies no captures, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2410 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
|
2411 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2414 As an example, the following loop |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2415 will iterate over all the words from string <code>s</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2416 printing one per line: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2417 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2418 <pre> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2419 local s = "hello world from Lua" |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2420 for w in String.gmatch(s, [[\w+]]) do |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2421 print(w) |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2422 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2423 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2424 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2425 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2426 The next example collects all pairs <code>key=value</code> from the |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2427 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
|
2428 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2429 <pre> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2430 local t = {} |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2431 local s = "from=world, to=Lua" |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2432 for k, v in String.gmatch(s, [[(\w+)=(\w+)]]) do |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2433 t[k] = v |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2434 end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2435 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2436 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2437 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2438 For this function, a caret '<code>^</code>' at the start of a pattern does not |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2439 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
|
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 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2443 <h4 heading><a name="String.gsub"><code>String.gsub (s, pattern, repl [, n])</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2444 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2445 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2446 Returns a copy of <code>s</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2447 in which all (or the first <code>n</code>, if given) |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2448 occurrences of the <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) have been |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2449 replaced by a replacement string specified by <code>repl</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2450 which can be a string, a table, or a function. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2451 <code>gsub</code> also returns, as its second value, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2452 the total number of matches that occurred. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2453 The name <code>gsub</code> comes from <em>Global SUBstitution</em>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2454 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2455 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2456 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2457 If <code>repl</code> is a string, then its value is used for replacement. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2458 The character <code>\</code> works as an escape character. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2459 Any sequence in <code>repl</code> of the form <code>$<em>d</em></code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2460 with <em>d</em> between 1 and 9, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2461 stands for the value of the <em>d</em>-th captured substring. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2462 The sequence <code>$0</code> stands for the whole match. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2463 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2464 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2465 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2466 If <code>repl</code> is a table, then the table is queried for every match, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2467 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
|
2468 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2469 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2470 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2471 If <code>repl</code> is a function, then this function is called every time a |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2472 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
|
2473 in order. |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2476 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2477 In any case, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2478 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
|
2479 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
|
2480 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2481 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2482 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2483 If the value returned by the table query or by the function call |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2484 is not <b>nil</b>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2485 then it is used as the replacement string; |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2486 otherwise, if it 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
|
2487 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
|
2488 (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
|
2489 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2490 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2491 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2492 Here are some examples: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2493 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2494 <pre> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2495 x = String.gsub("hello world", [[(\w+)]], "$1 $1") |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2496 --> 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
|
2497 |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2498 x = String.gsub("hello world", [[\w+]], "$0 $0", 1) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2499 --> x="hello hello world" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2500 |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2501 x = String.gsub("hello world from Luan", [[(\w+)\s*(\w+)]], "$2 $1") |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2502 --> x="world hello Luan from" |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2503 |
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2504 x = String.gsub("4+5 = $return 4+5$", [[\$(.*?)\$]], function (s) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2505 return load(s)() |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2506 end) |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2507 --> x="4+5 = 9" |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2508 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2509 local t = {name="lua", version="5.3"} |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2510 x = String.gsub("$name-$version.tar.gz", [[\$(\w+)]], t) |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2511 --> x="lua-5.3.tar.gz" |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2512 </pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2513 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2514 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2515 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2516 <h4 heading><a name="String.literal"><code>String.literal (s)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2517 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2518 Returns a string which matches the literal string <code>s</code> in a regular expression. This function is simply the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#quote(java.lang.String)"><code>Pattern.quote</code></a>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2519 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2520 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2521 <h4 heading><a name="String.lower"><code>String.lower (s)</code></a></h4> |
555
e25ba7a2e816
some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
553
diff
changeset
|
2522 <p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2523 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
|
2524 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
|
2525 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
|
2526 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2527 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2528 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2529 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2530 <h4 heading><a name="String.match"><code>String.match (s, pattern [, init])</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2531 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2532 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2533 Looks for the first <em>match</em> of |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2534 <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) in the string <code>s</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2535 If it finds one, then <code>match</code> returns |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2536 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
|
2537 otherwise it returns <b>nil</b>. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2538 If <code>pattern</code> specifies no captures, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2539 then the whole match is returned. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2540 A third, optional numerical argument <code>init</code> specifies |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2541 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
|
2542 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
|
2543 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2544 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2545 <h4 heading><a name="String.matches"><code>String.matches (s, pattern)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2546 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2547 Returns a boolean indicating whether the entire string <code>s</code> matches <code>pattern</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2548 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2549 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2550 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2551 <h4 heading><a name="String.rep"><code>String.rep (s, n [, sep])</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2552 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2553 Returns a string that is the concatenation of <code>n</code> copies of |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2554 the string <code>s</code> separated by the string <code>sep</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2555 The default value for <code>sep</code> is the empty string |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2556 (that is, no separator). |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2557 Returns the empty string if <code>n</code> is not positive. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2558 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2559 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2560 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2561 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2562 <h4 heading><a name="String.reverse"><code>String.reverse (s)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2563 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2564 Returns a string that is the string <code>s</code> reversed. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2565 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2566 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2567 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2568 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2569 <h4 heading><a name="String.sub"><code>String.sub (s, i [, j])</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2570 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2571 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2572 Returns the substring of <code>s</code> that |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2573 starts at <code>i</code> and continues until <code>j</code>; |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2574 <code>i</code> and <code>j</code> can be negative. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2575 If <code>j</code> is absent, then it is assumed to be equal to -1 |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2576 (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
|
2577 In particular, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2578 the call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2579 with length <code>j</code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2580 and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2581 with length <code>i</code>. |
371
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2585 If, after the translation of negative indices, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2586 <code>i</code> is less than 1, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2587 it is corrected to 1. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2588 If <code>j</code> is greater than the string length, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2589 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
|
2590 If, after these corrections, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2591 <code>i</code> is greater than <code>j</code>, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2592 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
|
2593 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2594 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2595 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2596 <h4 heading><a name="String.to_binary"><code>String.to_binary (s)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2597 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2598 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2599 Converts a string to a binary by calling the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes()"><code>String.getBytes</code></a>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2600 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2601 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2602 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2603 <h4 heading><a name="String.to_number"><code>String.to_number (s [, base])</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2604 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2605 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2606 When called with no <code>base</code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2607 <code>to_number</code> tries to convert its argument to a number. |
556
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2608 If the argument is |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2609 a string convertible to a number, |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2610 then <code>to_number</code> returns this number; |
556
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2611 otherwise, it returns <b>nil</b>. |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2612 |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2613 The conversion of strings can result in integers or floats. |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2614 |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2615 |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2616 <p> |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2617 When called with <code>base</code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2618 then <code>s</code> must be a string to be interpreted as |
556
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2619 an integer numeral in that base. |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2620 In bases above 10, the letter '<code>A</code>' (in either upper or lower case) |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2621 represents 10, '<code>B</code>' represents 11, and so forth, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2622 with '<code>Z</code>' representing 35. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2623 If the string <code>s</code> is not a valid numeral in the given base, |
556
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2624 the function returns <b>nil</b>. |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2625 |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2626 |
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2627 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2628 <h4 heading><a name="String.trim"><code>String.trim (s)</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2629 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2630 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2631 Removes the leading and trailing whitespace by calling the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#trim()"><code>String.trim</code></a>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2632 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2633 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2634 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2635 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2636 <h4 heading><a name="String.unicode"><code>String.unicode (s [, i [, j]])</code></a></h4> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2637 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2638 <p> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2639 Returns the internal numerical codes of the characters <code>s[i]</code>, |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2640 <code>s[i+1]</code>, ..., <code>s[j]</code>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2641 The default value for <code>i</code> is 1; |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2642 the default value for <code>j</code> is <code>i</code>. |
556
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2643 These indices are corrected |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2644 following the same rules of function <a href="#String.sub"><code>String.sub</code></a>. |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2645 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2646 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2647 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2648 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2649 |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
556
diff
changeset
|
2650 <h4 heading><a name="String.upper"><code>String.upper (s)</code></a></h4> |
556
d02f43598ba3
finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
555
diff
changeset
|
2651 <p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2652 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
|
2653 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
|
2654 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
|
2655 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
|
2656 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2657 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2658 |
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 |
567 | 2661 <h3 heading><a name="binary_lib">Binary Manipulation</a></h3> |
2662 | |
2663 <p> | |
2664 Include this library by: | |
2665 | |
2666 <pre> | |
2667 local Binary = require "luan:Binary" | |
2668 </pre> | |
2669 | |
2670 | |
2671 <h4 heading><a name="Binary.binary"><code>Binary.binary (···)</code></a></h4> | |
2672 | |
2673 <p> | |
2674 Receives zero or more bytes (as integers). | |
2675 Returns a binary with length equal to the number of arguments, | |
2676 in which each byte has the internal numerical code equal | |
2677 to its corresponding argument. | |
2678 | |
2679 | |
2680 <h4 heading><a name="Binary.byte"><code>Binary.byte (b [, i [, j]])</code></a></h4> | |
2681 | |
2682 <p> | |
2683 Returns the internal numerical codes of the bytes <code>b[i]</code>, | |
2684 <code>b[i+1]</code>, ..., <code>b[j]</code>. | |
2685 The default value for <code>i</code> is 1; | |
2686 the default value for <code>j</code> is <code>i</code>. | |
2687 These indices are corrected | |
2688 following the same rules of function <a href="#String.sub"><code>String.sub</code></a>. | |
2689 | |
2690 | |
2691 <h4 heading><a name="Binary.to_string"><code>Binary.to_string (b)</code></a></h4> | |
2692 <p> | |
2693 Converts the binary <code>b</code> to a string using the Java <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#String(byte[])">String constructor</a>. | |
2694 | |
371
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 |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2698 <h3 heading><a name="table_lib">Table Manipulation</a></h3> |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2699 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2700 <p> |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2701 Include this library by: |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2702 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2703 <pre> |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2704 local Table = require "luan:Table" |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2705 </pre> |
371
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2708 This library provides generic functions for table manipulation. |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2709 It provides all its functions inside the table <code>Table</code>. |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2710 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2711 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2712 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2713 <h4 heading><a name="Table.concat"><code>Table.concat (list [, sep [, i [, j]]])</code></a></h4> |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2714 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2715 <p> |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2716 Given a list, |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2717 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
|
2718 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
|
2719 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
|
2720 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
|
2721 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
|
2722 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2723 |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2724 <h4 heading><a name="Table.copy"><code>Table.copy (tbl [, i [, j]])</code></a></h4> |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2725 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2726 <p> |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2727 If <code>i</code> is <code>nil</code>, returns a shallow copy of <code>tbl</code>. |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2728 Otherwise returns a new table which is a list of the elements <code>tbl[i] ··· tbl[j]</code>. |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2729 By default, <code>j</code> is <code>#tbl</code>. |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2730 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2731 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2732 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2733 <h4 heading><a name="Table.insert"><code>Table.insert (list, pos, value)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2734 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2735 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2736 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
|
2737 shifting up the elements |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2738 <code>list[pos], list[pos+1], ···, list[#list]</code>. |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2739 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2740 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2741 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2742 <h4 heading><a name="Table.pack"><code>Table.pack (···)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2743 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2744 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2745 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
|
2746 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
|
2747 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
|
2748 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2749 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2750 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2751 |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2752 <h4 heading><a name="Table.remove"><code>Table.remove (list, pos)</code></a></h4> |
371
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 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
|
2757 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
|
2758 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
|
2759 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
|
2760 <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
|
2761 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
|
2762 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
|
2763 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
|
2764 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
|
2765 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2766 |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2767 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2768 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2769 <h4 heading><a name="Table.sort"><code>Table.sort (list [, comp])</code></a></h4> |
371
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2772 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
|
2773 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
|
2774 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
|
2775 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
|
2776 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
|
2777 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
|
2778 (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
|
2779 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
|
2780 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
|
2781 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2782 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2783 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
|
2784 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
|
2785 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
|
2786 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2787 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2788 |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2789 <h4 heading><a name="Table.unpack"><code>Table.unpack (list [, i [, j]])</code></a></h4> |
371
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2792 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
|
2793 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
|
2794 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2795 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2796 return list[i], list[i+1], ···, list[j] |
565
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2797 </pre> |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2798 |
22bfd8a2eaee
do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents:
562
diff
changeset
|
2799 <p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2800 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
|
2801 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2802 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2803 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2804 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2805 <h3 heading><a name="number_lib">Number Manipulation</a></h3> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2806 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2807 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2808 Include this library by: |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2809 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2810 <pre> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2811 local Number = require "luan:Number" |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2812 </pre> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2813 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2814 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2815 <h4 heading><a name="Number.double"><code>Number.double (x)</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2816 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2817 Returns <code>x</code> as a double. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2818 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2819 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2820 <h4 heading><a name="Number.integer"><code>Number.integer (x)</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2821 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2822 If the value <code>x</code> is convertible to an integer, |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2823 returns that integer. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2824 Otherwise throws an error. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2825 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2826 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2827 <h4 heading><a name="Number.long"><code>Number.long (x)</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2828 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2829 If the value <code>x</code> is convertible to an long, |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2830 returns that long. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2831 Otherwise throws an error. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2832 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2833 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2834 <h4 heading><a name="Number.long_to_string"><code>Number.long_to_string (i, radix)</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2835 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2836 Converts long value <code>i</code> to a string by calling <code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#toString(long,%20int)">Long.toString</a></code>. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2837 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2838 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2839 <h4 heading><a name="Number.type"><code>Number.type (x)</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2840 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2841 Returns a string for the numeric type of <code>x</code>. Possible return values include "<code>integer</code>", "<code>long</code>", "<code>double</code>", and "<code>float</code>". |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2842 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2843 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2844 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2845 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2846 <h3 heading><a name="math_lib">Mathematical Functions</a></h3> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2847 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2848 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2849 Include this library by: |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2850 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2851 <pre> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2852 local Math = require "luan:Math" |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2853 </pre> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2854 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2855 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2856 This library provides basic mathematical functions. |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2857 It provides all its functions and constants inside the table <code>Math</code>. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2858 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2859 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2860 <h4 heading><a name="Math.abs"><code>Math.abs (x)</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2861 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2862 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2863 Returns the absolute value of <code>x</code>. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2864 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2865 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2866 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2867 <h4 heading><a name="Math.acos"><code>Math.acos (x)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2868 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2869 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2870 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
|
2871 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2874 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2875 <h4 heading><a name="Math.asin"><code>Math.asin (x)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2876 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2877 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2878 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
|
2879 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2880 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2881 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2882 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2883 <h4 heading><a name="Math.atan"><code>Math.atan (y, x)</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2884 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2885 <p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2886 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
|
2887 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
|
2888 quadrant of the result. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2889 (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
|
2890 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2891 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2892 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2893 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2894 <h4 heading><a name="Math.ceil"><code>Math.ceil (x)</code></a></h4> |
371
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2897 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
|
2898 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2899 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2900 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2901 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2902 <h4 heading><a name="Math.cos"><code>Math.cos (x)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2903 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2904 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2905 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
|
2906 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2907 |
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 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2910 <h4 heading><a name="Math.deg"><code>Math.deg (x)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2911 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2912 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2913 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
|
2914 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2915 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2916 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2917 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2918 <h4 heading><a name="Math.exp"><code>Math.exp (x)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2919 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2920 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2921 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
|
2922 (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
|
2923 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2924 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2925 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2926 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2927 <h4 heading><a name="Math.floor"><code>Math.floor (x)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2928 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2929 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2930 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
|
2931 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2932 |
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 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2935 <h4 heading><a name="Math.fmod"><code>Math.fmod (x, y)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2936 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2937 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2938 Returns the remainder of the division of <code>x</code> by <code>y</code> |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2939 that rounds the quotient towards zero. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2940 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2941 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2942 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2943 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2944 <h4 heading><a name="Math.huge"><code>Math.huge</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2945 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2946 <p> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2947 A value larger than any other numerical value. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2948 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2949 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2950 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2951 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2952 <h4 heading><a name="Math.log"><code>Math.log (x [, base])</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2953 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2954 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2955 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
|
2956 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
|
2957 (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
|
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2961 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2962 <h4 heading><a name="Math.max"><code>Math.max (x, ···)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2963 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2964 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2965 Returns the argument with the maximum value, |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2966 according to the Lua operator <code><</code>. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2967 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2968 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2969 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2970 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2971 <h4 heading><a name="Math.max_integer"><code>Math.max_integer</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2972 <p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2973 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
|
2974 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2975 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2976 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2977 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2978 <h4 heading><a name="Math.min"><code>Math.min (x, ···)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2979 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2980 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2981 Returns the argument with the minimum value, |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2982 according to the Lua operator <code><</code>. |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2983 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2984 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2985 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2986 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2987 <h4 heading><a name="Math.min_integer"><code>Math.min_integer</code></a></h4> |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2988 <p> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2989 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
|
2990 |
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 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2994 <h4 heading><a name="Math.modf"><code>Math.modf (x)</code></a></h4> |
371
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2997 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>. |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2998 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
2999 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3000 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3001 |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3002 <h4 heading><a name="Math.pi"><code>Math.pi</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3003 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3004 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3005 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
|
3006 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3007 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3008 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3009 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3010 <h4 heading><a name="Math.rad"><code>Math.rad (x)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3011 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3012 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3013 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
|
3014 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3015 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3016 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3017 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3018 <h4 heading><a name="Math.random"><code>Math.random ([m [, n])</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3019 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3020 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3021 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3022 When called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3023 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
|
3024 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
|
3025 When called with two integers <code>m</code> and <code>n</code>, |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3026 <code>Math.random</code> returns a pseudo-random integer |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3027 with uniform distribution in the range <em>[m, n]</em>. |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3028 (The value <em>m-n</em> cannot be negative and must fit in a Luan integer.) |
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3029 The call <code>Math.random(n)</code> is equivalent to <code>Math.random(1,n)</code>. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3030 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3031 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3032 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3033 This function is an interface to the underling |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3034 pseudo-random generator function provided by Java. |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3035 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
|
3036 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3037 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3038 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3039 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3040 <h4 heading><a name="Math.sin"><code>Math.sin (x)</code></a></h4> |
371
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3041 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3042 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3043 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
|
3044 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3045 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3046 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3047 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3048 <h4 heading><a name="Math.sqrt"><code>Math.sqrt (x)</code></a></h4> |
371
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3051 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
|
3052 (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
|
3053 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3054 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3055 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3056 |
566
90b93790c544
Number and Math documentation and minor changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
565
diff
changeset
|
3057 <h4 heading><a name="Math.tan"><code>Math.tan (x)</code></a></h4> |
371
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 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
|
3061 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3062 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3063 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3067 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3068 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3069 <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
|
3070 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3071 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3072 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
|
3073 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
|
3074 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
|
3075 default output file, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3076 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
|
3077 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
|
3078 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3079 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3080 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3081 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
|
3082 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
|
3083 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
|
3084 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
|
3085 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
|
3086 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3087 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3088 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3089 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
|
3090 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
|
3091 <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
|
3092 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
|
3093 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3094 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3095 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3096 Unless otherwise stated, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3097 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
|
3098 (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
|
3099 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
|
3100 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
|
3101 On non-POSIX systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3102 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
|
3103 in case of errors |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3104 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
|
3105 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
|
3106 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3107 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3108 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3109 <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
|
3110 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3111 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3112 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3113 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
|
3114 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
|
3115 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3116 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3117 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3118 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3119 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3120 <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
|
3121 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3124 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
|
3125 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3126 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3127 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3130 <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
|
3131 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3134 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
|
3135 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
|
3136 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
|
3137 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
|
3138 When called without parameters, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3139 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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3143 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
|
3144 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
|
3145 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3146 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3147 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3148 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3149 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3150 <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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3154 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
|
3155 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
|
3156 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
|
3157 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
|
3158 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
|
3159 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3160 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3161 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3162 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
|
3163 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
|
3164 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
|
3165 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
|
3166 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3167 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3168 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3169 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
|
3170 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
|
3171 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3172 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3173 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3174 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3175 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3176 <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
|
3177 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3180 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
|
3181 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
|
3182 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
|
3183 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
|
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 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
|
3188 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3189 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3190 <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
|
3191 <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
|
3192 <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
|
3193 <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
|
3194 <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
|
3195 <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
|
3196 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
|
3197 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3198 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
|
3199 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
|
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3203 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3204 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3205 <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
|
3206 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3207 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3208 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3209 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
|
3210 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3211 |
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 <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
|
3216 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3217 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3218 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3219 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
|
3220 on all platforms. |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3224 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
|
3225 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
|
3226 (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
|
3227 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
|
3228 (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
|
3229 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3230 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3231 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3232 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3233 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3234 <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
|
3235 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3238 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
|
3239 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3240 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3241 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3244 <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
|
3245 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3246 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3247 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3248 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
|
3249 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
|
3250 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
|
3251 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3256 <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
|
3257 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3260 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
|
3261 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
|
3262 <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
|
3263 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
|
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-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
|
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 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
|
3274 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3275 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3276 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3277 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3278 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3279 <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
|
3280 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3281 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3282 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3283 Closes <code>file</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3284 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
|
3285 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
|
3286 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
|
3287 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3290 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
|
3291 <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
|
3292 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
|
3293 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3297 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3298 <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
|
3299 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3300 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3301 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3302 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
|
3303 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3304 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3305 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3308 <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
|
3309 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3310 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3311 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3312 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
|
3313 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
|
3314 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
|
3315 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
|
3316 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
|
3317 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
|
3318 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3319 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3320 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
|
3321 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3322 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
|
3323 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
|
3324 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
|
3325 when the loop ends. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3326 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3327 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3328 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3329 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
|
3330 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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3336 <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
|
3337 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3338 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3339 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3340 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
|
3341 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
|
3342 For each format, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3343 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
|
3344 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
|
3345 (In this latter case, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3346 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
|
3347 When called without formats, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3348 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
|
3349 (see below). |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3350 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3353 The available formats are |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3354 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3355 <ul> |
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 <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
|
3358 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
|
3359 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
|
3360 (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
|
3361 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
|
3362 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
|
3363 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
|
3364 (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
|
3365 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
|
3366 </li> |
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 <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
|
3369 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
|
3370 </li> |
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 <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
|
3373 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
|
3374 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
|
3375 </li> |
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 <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
|
3378 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
|
3379 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
|
3380 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
|
3381 </li> |
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 <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
|
3384 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
|
3385 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
|
3386 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3387 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3388 <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
|
3389 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
|
3390 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
|
3391 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
|
3392 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
|
3393 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
|
3394 </li> |
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 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3397 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
|
3398 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3399 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3400 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3403 <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
|
3404 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3407 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
|
3408 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
|
3409 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
|
3410 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
|
3411 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3412 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3413 <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
|
3414 <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
|
3415 <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
|
3416 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3417 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
|
3418 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
|
3419 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
|
3420 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
|
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 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
|
3425 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
|
3426 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
|
3427 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
|
3428 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
|
3429 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
|
3430 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
|
3431 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
|
3432 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3433 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3434 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3435 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3436 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3437 <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
|
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 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
|
3442 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
|
3443 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3444 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3445 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3446 <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
|
3447 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
|
3448 </li> |
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 <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
|
3451 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
|
3452 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
|
3453 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
|
3454 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3455 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3456 <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
|
3457 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
|
3458 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
|
3459 (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
|
3460 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3461 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3462 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3463 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
|
3464 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
|
3465 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
|
3466 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3467 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3471 <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
|
3472 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3473 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3474 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3475 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
|
3476 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
|
3477 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3478 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3479 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3480 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
|
3481 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
|
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3485 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3489 <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
|
3490 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3491 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3492 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
|
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-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
|
3497 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3500 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
|
3501 used by the program. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3502 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3503 |
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 <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
|
3508 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3511 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
|
3512 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
|
3513 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3514 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3515 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3516 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
|
3517 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
|
3518 (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
|
3519 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
|
3520 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3521 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3522 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3523 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
|
3524 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
|
3525 After this optional character, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3526 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
|
3527 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
|
3528 <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
|
3529 <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
|
3530 <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
|
3531 <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
|
3532 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
|
3533 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
|
3534 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
|
3535 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3536 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3537 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3538 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
|
3539 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
|
3540 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
|
3541 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3542 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3543 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3544 When called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3545 <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
|
3546 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
|
3547 (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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3551 On non-POSIX systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3552 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
|
3553 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
|
3554 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3555 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3556 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3557 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3558 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3559 <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
|
3560 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3561 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3562 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3563 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
|
3564 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
|
3565 (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
|
3566 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
|
3567 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
|
3568 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3569 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3573 <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
|
3574 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3575 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3576 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3577 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
|
3578 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
|
3579 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
|
3580 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
|
3581 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
|
3582 After this first result |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3583 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
|
3584 as follows: |
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 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3587 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3588 <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
|
3589 the command terminated normally; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3590 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
|
3591 </li> |
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 <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
|
3594 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
|
3595 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
|
3596 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3597 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3598 </ul> |
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 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
|
3602 <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
|
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-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
|
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 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
|
3613 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
|
3614 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
|
3615 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
|
3616 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
|
3617 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
|
3618 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
|
3619 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
|
3620 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3621 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3622 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3623 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
|
3624 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
|
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-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
|
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 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
|
3635 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
|
3636 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3641 <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
|
3642 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3645 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
|
3646 with the given name. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3647 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
|
3648 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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3654 <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
|
3655 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3656 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3657 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3658 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
|
3659 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
|
3660 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
|
3661 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3662 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3663 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3664 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3665 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3666 <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
|
3667 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3668 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3669 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3670 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
|
3671 <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
|
3672 <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
|
3673 <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
|
3674 <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
|
3675 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
|
3676 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
|
3677 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
|
3678 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3679 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3680 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3681 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
|
3682 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
|
3683 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
|
3684 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
|
3685 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3686 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3687 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3688 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
|
3689 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
|
3690 for the given category. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3691 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3692 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3693 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3694 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
|
3695 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
|
3696 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3700 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3701 <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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3705 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
|
3706 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
|
3707 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
|
3708 and may have fields |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3709 <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
|
3710 <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
|
3711 <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
|
3712 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
|
3713 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
|
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 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
|
3718 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
|
3719 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
|
3720 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
|
3721 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
|
3722 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
|
3723 <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
|
3724 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3725 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3726 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3729 <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
|
3730 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3731 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3732 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3733 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
|
3734 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
|
3735 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
|
3736 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
|
3737 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3740 On POSIX systems, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3741 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
|
3742 to avoid security risks. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3743 (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
|
3744 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
|
3745 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
|
3746 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
|
3747 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3748 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3749 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3750 When possible, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3751 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
|
3752 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
|
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3756 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3757 |
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 <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
|
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 This library provides |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3764 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
|
3765 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
|
3766 Several of its functions |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3767 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
|
3768 (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
|
3769 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
|
3770 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
|
3771 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
|
3772 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
|
3773 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
|
3774 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3777 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
|
3778 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
|
3779 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
|
3780 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
|
3781 thread to operate over. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3782 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
|
3783 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3784 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3785 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3786 <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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3790 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
|
3791 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
|
3792 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
|
3793 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
|
3794 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
|
3795 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
|
3796 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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3800 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
|
3801 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
|
3802 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3806 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3807 <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
|
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 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
|
3812 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
|
3813 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
|
3814 (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
|
3815 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3820 <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
|
3821 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3824 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
|
3825 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
|
3826 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
|
3827 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
|
3828 of the given thread: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3829 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
|
3830 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
|
3831 (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
|
3832 and so on. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3833 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
|
3834 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
|
3835 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3836 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3837 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3838 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
|
3839 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
|
3840 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
|
3841 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
|
3842 If present, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3843 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
|
3844 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
|
3845 If present, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3846 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
|
3847 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
|
3848 valid lines. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3849 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3850 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3851 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3852 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
|
3853 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
|
3854 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
|
3855 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
|
3856 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
|
3857 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
|
3858 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3859 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3860 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3863 <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
|
3864 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3865 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3866 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3867 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
|
3868 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
|
3869 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
|
3870 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
|
3871 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3872 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3873 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3874 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
|
3875 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
|
3876 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
|
3877 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
|
3878 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
|
3879 -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
|
3880 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
|
3881 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
|
3882 (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
|
3883 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3884 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3885 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3886 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
|
3887 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
|
3888 (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
|
3889 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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3893 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
|
3894 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
|
3895 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3899 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3900 <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
|
3901 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3902 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3903 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3904 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
|
3905 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
|
3906 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3907 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3908 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3909 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3910 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3911 <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
|
3912 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3915 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
|
3916 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3917 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3921 <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
|
3922 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3923 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3924 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3925 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
|
3926 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
|
3927 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
|
3928 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3929 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3930 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3931 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
|
3932 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
|
3933 (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
|
3934 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3935 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3936 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3939 <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
|
3940 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3943 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
|
3944 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
|
3945 returns <b>nil</b>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3946 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3947 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3948 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3949 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3950 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3951 <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
|
3952 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3953 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3954 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3955 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
|
3956 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
|
3957 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
|
3958 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
|
3959 with the given meaning: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3960 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3961 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3962 <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
|
3963 <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
|
3964 <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
|
3965 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3966 Moreover, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3967 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
|
3968 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
|
3969 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3970 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3971 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3972 When called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3973 <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
|
3974 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3975 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3976 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3977 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
|
3978 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
|
3979 <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
|
3980 <code>"return"</code>, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3981 <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
|
3982 For line events, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3983 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
|
3984 Inside a hook, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3985 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
|
3986 the running function |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3987 (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
|
3988 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
|
3989 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3990 |
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 <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
|
3995 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3996 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3997 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3998 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
|
3999 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
|
4000 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
|
4001 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
|
4002 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
|
4003 (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
|
4004 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
|
4005 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4006 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4007 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4008 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
|
4009 variable indices and names. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4010 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4011 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4012 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4013 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4014 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4015 <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
|
4016 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4017 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4018 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4019 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
|
4020 (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
|
4021 Returns <code>value</code>. |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4024 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4027 <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
|
4028 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4029 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4030 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4031 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
|
4032 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
|
4033 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
|
4034 with the given index. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4035 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
|
4036 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4037 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4038 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4039 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4040 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4041 <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
|
4042 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4043 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4044 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4045 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
|
4046 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
|
4047 <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
|
4048 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4049 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4050 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4051 Returns <code>udata</code>. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4052 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4057 <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
|
4058 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4061 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
|
4062 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
|
4063 Otherwise, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4064 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
|
4065 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
|
4066 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
|
4067 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
|
4068 to start the traceback |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4069 (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
|
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4075 <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
|
4076 |
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 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
|
4080 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
|
4081 from the given function. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4082 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4083 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4084 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4085 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
|
4086 closures share upvalues. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4087 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
|
4088 (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
|
4089 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
|
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4094 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4095 <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
|
4096 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4097 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4098 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4099 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
|
4100 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
|
4101 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4102 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4103 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4104 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4105 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4106 |
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 <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
|
4109 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4110 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4111 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
|
4112 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
|
4113 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
|
4114 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
|
4115 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
|
4116 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
|
4117 The standalone interpreter includes |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4118 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
|
4119 Its usage is: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4120 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4121 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4122 lua [options] [script [args]] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4123 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4124 The options are: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4125 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4126 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4127 <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
|
4128 <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
|
4129 <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
|
4130 <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
|
4131 <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
|
4132 <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
|
4133 <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
|
4134 </ul><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4135 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
|
4136 When called without arguments, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4137 <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
|
4138 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
|
4139 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
|
4140 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4143 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
|
4144 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
|
4145 (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
|
4146 before running any argument. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4147 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
|
4148 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
|
4149 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
|
4150 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4151 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4152 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4153 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
|
4154 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
|
4155 Lua also ignores |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4156 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
|
4157 setting the values of |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4158 <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
|
4159 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
|
4160 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4163 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
|
4164 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
|
4165 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4166 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4167 $ 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
|
4168 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4169 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
|
4170 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
|
4171 (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
|
4172 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4173 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4174 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4175 Before running any code, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4176 <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
|
4177 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
|
4178 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
|
4179 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
|
4180 and so on. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4181 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
|
4182 (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
|
4183 go to negative indices. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4184 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
|
4185 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4186 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4187 $ 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
|
4188 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4189 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
|
4190 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4191 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4192 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
|
4193 [0] = "b.lua", |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4194 [1] = "t1", [2] = "t2" } |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4195 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4196 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
|
4197 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
|
4198 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
|
4199 For instance, the call |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4200 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4201 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4202 $ 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
|
4203 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4204 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
|
4205 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
|
4206 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
|
4207 <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
|
4208 (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
|
4209 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
|
4210 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4211 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4212 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4213 In interactive mode, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4214 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
|
4215 After reading a line, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4216 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
|
4217 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
|
4218 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
|
4219 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
|
4220 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
|
4221 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
|
4222 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4225 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
|
4226 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
|
4227 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
|
4228 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
|
4229 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
|
4230 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
|
4231 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
|
4232 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4233 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4234 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4235 When finishing normally, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4236 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
|
4237 (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
|
4238 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
|
4239 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
|
4240 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4241 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4242 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4243 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
|
4244 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
|
4245 the standalone interpreter skips |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4246 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
|
4247 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
|
4248 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
|
4249 as in |
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 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4252 #!/usr/local/bin/lua |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4253 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4254 (Of course, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4255 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
|
4256 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
|
4257 then |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4258 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4259 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4260 #!/usr/bin/env lua |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4261 </pre><p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4262 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
|
4263 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4264 |
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 <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
|
4267 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4268 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4269 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
|
4270 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
|
4271 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
|
4272 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
|
4273 However, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4274 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
|
4275 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4276 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4277 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4278 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
|
4279 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
|
4280 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
|
4281 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
|
4282 Therefore, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4283 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
|
4284 different Lua versions. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4285 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
|
4286 using a new version. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4287 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4288 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4289 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4290 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
|
4291 of precompiled chunks; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4292 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
|
4293 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4294 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4295 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4296 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
|
4297 change between versions. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4298 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4299 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4300 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4301 <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
|
4302 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4303 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4304 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4305 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
|
4306 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
|
4307 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
|
4308 some computations |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4309 (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
|
4310 can give different results. |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4314 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
|
4315 (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
|
4316 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
|
4317 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
|
4318 (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
|
4319 for an occasional incompatibility; |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4320 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
|
4321 For good programming, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4322 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
|
4323 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
|
4324 </li> |
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 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4327 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
|
4328 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
|
4329 (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
|
4330 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
|
4331 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
|
4332 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
|
4333 |
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 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4336 (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
|
4337 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
|
4338 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
|
4339 </li> |
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 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4342 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
|
4343 (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
|
4344 </li> |
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 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4347 |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4350 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4351 <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
|
4352 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4353 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4354 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4355 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
|
4356 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
|
4357 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
|
4358 (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
|
4359 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
|
4360 </li> |
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 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4363 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
|
4364 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
|
4365 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4366 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4367 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4368 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
|
4369 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
|
4370 </li> |
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 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4373 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
|
4374 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
|
4375 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4376 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4377 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4378 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
|
4379 <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
|
4380 <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
|
4381 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
|
4382 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
|
4383 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
|
4384 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
|
4385 For the other operations, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4386 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
|
4387 implement them in Lua. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4388 </li> |
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 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4391 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
|
4392 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
|
4393 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
|
4394 (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
|
4395 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
|
4396 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
|
4397 (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
|
4398 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
|
4399 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4400 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4401 </ul> |
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 <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
|
4407 |
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 <ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4410 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4411 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4412 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
|
4413 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
|
4414 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
|
4415 Adapt your code accordingly. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4416 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4417 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4418 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4419 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
|
4420 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
|
4421 </li> |
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 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4424 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
|
4425 (<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
|
4426 <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
|
4427 were deprecated. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4428 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
|
4429 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4430 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4431 <li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4432 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
|
4433 (<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
|
4434 were deprecated. |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4435 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
|
4436 (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
|
4437 </li> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4438 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4439 </ul> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4440 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4441 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4442 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4443 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4444 <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
|
4445 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4446 <p> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4447 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
|
4448 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
|
4449 {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
|
4450 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
|
4451 (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
|
4452 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
|
4453 Name, Numeral, |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4454 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
|
4455 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4456 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4457 |
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 <pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4460 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4461 chunk ::= block |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4462 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4463 block ::= {stat} [retstat] |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4464 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4465 stat ::= ‘<b>;</b>’ | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4466 varlist ‘<b>=</b>’ explist | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4467 functioncall | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4468 label | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4469 <b>break</b> | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4470 <b>goto</b> Name | |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4471 <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
|
4472 <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
|
4473 <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
|
4474 <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
|
4475 <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
|
4476 <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
|
4477 <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
|
4478 <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
|
4479 <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
|
4480 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4481 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
|
4482 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4483 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
|
4484 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4485 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
|
4486 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4487 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
|
4488 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4489 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
|
4490 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4491 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
|
4492 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4493 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
|
4494 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4495 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
|
4496 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
|
4497 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4498 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
|
4499 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4500 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
|
4501 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4502 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
|
4503 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4504 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
|
4505 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4506 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
|
4507 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4508 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
|
4509 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4510 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
|
4511 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4512 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
|
4513 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4514 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
|
4515 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4516 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
|
4517 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4518 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
|
4519 ‘<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
|
4520 ‘<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
|
4521 <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
|
4522 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4523 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
|
4524 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4525 </pre> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4526 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4527 <p> |
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 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4530 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4531 |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4532 |
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 <HR> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4537 <SMALL CLASS="footer"> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4538 Last update: |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4539 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
|
4540 </SMALL> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4541 <!-- |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4542 Last change: minor edit |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4543 --> |
e01cddba3433
add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4544 |
372 | 4545 </div> |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
4546 |
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
|
4547 </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
|
4548 </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
|
4549 <% |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
382
diff
changeset
|
4550 end |