annotate website/src/manual.html.luan @ 559:bfb2c30324c0

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 23 Jun 2015 03:25:43 -0600
parents d02f43598ba3
children 7cc9d4a53d3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
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 local heading_options = Shared.heading_options
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
7bc63886d4f2 web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents: 503
diff changeset
9 return function()
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 382
diff changeset
10 Io.stdout = Http.response.text_writer()
391
2f5cc9c2cbf0 replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
11 %>
2f5cc9c2cbf0 replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
12 <html>
2f5cc9c2cbf0 replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
13 <head>
2f5cc9c2cbf0 replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
14 <% Html.simply_html_head() %>
2f5cc9c2cbf0 replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
15 <title>Luan Reference Manual</title>
2f5cc9c2cbf0 replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
16 </head>
2f5cc9c2cbf0 replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
17 <body>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 382
diff changeset
18
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
19 <div container>
387
23d075ce1e48 add website/src/Shared.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 386
diff changeset
20 <% Shared.header() %>
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
21
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
22 <h1>Luan Reference Manual</h1>
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
23
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <small>
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
26 Original copyright &copy; 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
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
28 <a href="http://www.lua.org/license.html">Lua license</a>.
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
29 Modified for Luan.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 </small>
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
31 </p>
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
32
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
33 <hr/>
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
34
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
35 <h2>Contents</h2>
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
36
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
37 <div margin-bottom="1em"><a href="#intro">Introduction</a></div>
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
38
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
39 <div margin-bottom="1em">
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
40 <a href="#basic">Basic Concepts</a>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
41 <ul>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
42 <li><a href="#types">Values and Types</a></li>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
43 <li><a href="#env">Environments</a></li>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
44 <li><a href="#error">Error Handling</a></li>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
45 <li><a href="#meta">Metatables and Metamethods</a></li>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
46 <li><a href="#gc">Garbage Collection</a></li>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
47 </ul>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
48 </div>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
49
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
50 <div margin-bottom="1em">
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
51 <a href="#lang">The Language</a>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
52 <ul>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
53 <li><a href="#lex">Lexical Conventions</a></li>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
54 <li><a href="#vars">Variables</a></li>
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
55 <li>
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
56 <a href="#stmts">Statements</a>
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
57 <ul>
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
58 <li><a href="#blocks">Blocks</a></li>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
59 <li><a href="#chunks">Chunks</a></li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
60 <li><a href="#assignment">Assignment</a></li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
61 <li><a href="#control">Control Structures</a></li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
62 <li><a href="#for">For Statement</a></li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
63 <li><a href="#fn_stmt">Function Calls as Statements</a></li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
64 <li><a href="#local_stmt">Local Declarations</a></li>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
65 <li><a href="#template_stmt">Template Statements</a></li>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
66 </ul>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
67 </li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
68 <li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
69 <a href="#expressions">Expressions</a>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
70 <ul>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
71 <li><a href="#arithmetic">Arithmetic Operators</a></li>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
72 <li><a href="#conversions">Coercions and Conversions</a></li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
73 <li><a href="#relational">Relational Operators</a></li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
74 <li><a href="#logical_ops">Logical Operators</a></li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
75 <li><a href="#concatenation">Concatenation</a></li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
76 <li><a href="#length">The Length Operator</a></li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
77 <li><a href="#precedence">Precedence</a></li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
78 <li><a href="#constructors">Table Constructors</a></li>
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
79 <li><a href="#fn_calls">Function Calls</a></li>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
80 <li><a href="#fn_def">Function Definitions</a></li>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
81 <li><a href="#template_expr">Template Expressions</a></li>
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
82 </ul>
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
83 </li>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
84 <li><a href="#visibility">Visibility Rules</a></li>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
85 </ul>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
86 </div>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
87
468
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
88 <div margin-bottom="1em">
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
89 <a href="#libs">Standard Libraries</a>
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
90 <ul>
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
91 <li><a href="#default_lib">Default Environment</a></li>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
92 <li><a href="#luan_lib">Basic Functions</a></li>
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
93 <li><a href="#package_lib">Modules</a></li>
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
94 <li><a href="#string_lib">String Manipulation</a></li>
468
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
95 </ul>
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
96 </div>
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
97
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
98 <hr/>
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
99
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
100
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
101 <h2 <%=heading_options%> ><a name="intro">Introduction</a></h2>
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
102
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
103 <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>
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
104
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
105 <p>Luan is implemented in Java and is tightly coupled with Java. So it makes a great scripting language for Java programmers.</p>
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
106
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
107 <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
108
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
110 <h2 <%=heading_options%> ><a name="basic">Basic Concepts</a></h2>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
111
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
112 <p>This section describes the basic concepts of the language.</p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
113
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
114 <h3 <%=heading_options%> ><a name="types">Values and Types</a></h3>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
115
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
116 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
117 Luan is a <i>dynamically typed language</i>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 This means that
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 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
120 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
121 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
122
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 <p>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
125 All values in Luan are <i>first-class values</i>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 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
127 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
128
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130 <p>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
131 There are eight basic types in Luan:
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
132 <i>nil</i>, <i>boolean</i>, <i>number</i>,
513
0dfc01d8d42d rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents: 512
diff changeset
133 <i>string</i>, <i>binary</i>, <i>function</i>, <i>java</i>,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
134 and <i>table</i>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
135 <i>Nil</i> is the type of the value <b>nil</b>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 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
137 it usually represents the absence of a useful value.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
138 <i>Nil</i> is implemented as the Java value <i>null</i>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
139 <i>Boolean</i> is the type of the values <b>false</b> and <b>true</b>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
140 <i>Boolean</i> is implemented as the Java class <i>Boolean</i>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
141 <i>Number</i> represents both
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 integer numbers and real (floating-point) numbers.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
143 <i>Number</i> is implemented as the Java class <i>Number</i>. Any Java subclass of <i>Number</i> is allowed and this is invisible to the Luan user. Operations on numbers follow the same rules of
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
144 the underlying Java implementation.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
145
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
146 <i>String</i> is implemented as the Java class <i>String</i>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
147 <i>Binary</i> is implemented as the Java type <i>byte[]</i>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
148
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
149
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
150 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
151 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
152 functions written in Java (see <a href="#fn_calls">Function Calls</a>).
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
153 Both are represented by the type <i>function</i>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
154
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
155
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
156 <p>
513
0dfc01d8d42d rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents: 512
diff changeset
157 The type <i>java</i> is provided to allow arbitrary Java objects to
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
158 be stored in Luan variables.
513
0dfc01d8d42d rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents: 512
diff changeset
159 A <i>java</i> value is a Java object that isn't one of the standard Luan types.
0dfc01d8d42d rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents: 512
diff changeset
160 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
161 except assignment and identity test.
513
0dfc01d8d42d rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents: 512
diff changeset
162 Java values are useful when Java access is enabled in Luan
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
163
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
164
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
165
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
166 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
167 The type <i>table</i> implements associative arrays,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 that is, arrays that can be indexed not only with numbers,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
169 but with any Luan value except <b>nil</b>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
170 Tables can be <i>heterogeneous</i>;
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171 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
172 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
173 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
174 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
175
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 <p>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
178 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
179 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
180 symbol tables, sets, records, graphs, trees, etc.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
181 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
182 The language supports this representation by
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
183 providing <tt>a.name</tt> as syntactic sugar for <tt>a["name"]</tt>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
184 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
185 (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
186
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 <p>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
189 We use the term <i>sequence</i> to denote a table where
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
190 the set of all positive numeric keys is equal to {1..<i>n</i>}
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
191 for some non-negative integer <i>n</i>,
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
192 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
193
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196 Like indices,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197 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
198 In particular,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199 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
200 table fields can contain functions.
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
201 Thus tables can also carry <i>methods</i> (see <a href="#fn_def">Function Definitions</a>).
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
203
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
204 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205 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
206 the definition of raw equality in the language.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
207 The expressions <tt>a[i]</tt> and <tt>a[j]</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208 denote the same table element
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
209 if and only if <tt>i</tt> and <tt>j</tt> are raw equal
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
210 (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
211 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
212 are equal to their respective integers
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
213 (e.g., <tt>1.0 == 1</tt>).
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
214
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
215
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
216 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
217 Luan values are <i>objects</i>:
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
218 variables do not actually <i>contain</i> values,
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
219 only <i>references</i> to them.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
220 Assignment, parameter passing, and function returns
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
221 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
222 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
223
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
224
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
225 <p>
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
226 The library function <a href="#Luan.type"><tt>Luan.type</tt></a> returns a string describing the type
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
227 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
228
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
230
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
231
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
233 <h3 <%=heading_options%> ><a name="env">Environments</a></h3>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
234
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
235 <p>
512
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
236 The environment of a chunk starts with only two local variables: <tt><a href="#require">require</a></tt> and <tt><a href="#java">java</a></tt>. 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>.
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
237
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
238 <p>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
239 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
240 any reference to a free name
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
241 (that is, a name not bound to any declaration) <tt>var</tt>
512
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
242 can be syntactically translated to <tt>_ENV.var</tt> if <tt>_ENV</tt> is defined.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
243
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
244
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
245 <h3 <%=heading_options%> ><a name="error">Error Handling</a></h3>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
246
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
247 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
248 Luan code can explicitly generate an error by calling the
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
249 <a href="#Luan.error"><tt>error</tt></a> function.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
250 If you need to catch errors in Luan,
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
251 you can use <a href="#Luan.pcall"><tt>pcall</tt></a> or <a href="#Luan.try"><tt>try</tt></a>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
252 to call a given function in <i>protected mode</i>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
253
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
254
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
255 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
256 Whenever there is an error,
482
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
257 an <i>error table</i>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
258 is propagated with information about the error.
482
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
259 See <a href="#Luan.new_error"><tt>Luan.new_error</tt></a>.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
260
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
261
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
262
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
263 <h3 <%=heading_options%> ><a name="meta">Metatables and Metamethods</a></h3>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
264
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
265 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
266 Every table in Luan can have a <i>metatable</i>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
267 This <i>metatable</i> is an ordinary Luan table
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268 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
269 under certain special operations.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
270 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
271 of operations over a value by setting specific fields in its metatable.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
272 For instance, when a table is the operand of an addition,
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
273 Luan checks for a function in the field "<tt>__add</tt>" of the table's metatable.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
274 If it finds one,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
275 Luan calls this function to perform the addition.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
276
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
277
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
278 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
279 The keys in a metatable are derived from the <i>event</i> names;
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
280 the corresponding values are called <ii>metamethods</i>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
281 In the previous example, the event is <tt>"add"</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282 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
283
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
284
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
285 <p>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
286 You can query the metatable of any table
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
287 using the <a href="#Luan.get_metatable"><tt>get_metatable</tt></a> function.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
289
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
290 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
291 You can replace the metatable of tables
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
292 using the <a href="#Luan.set_metatable"><tt>set_metatable</tt></a> function.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
293
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
294
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
295 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
296 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
297 arithmetic operations, bitwise operations,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
298 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
299
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
300
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
301 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
302 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
303 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
304 The key for each event is a string with its name prefixed by
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
305 two underscores, '<tt>__</tt>';
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
306 for instance, the key for operation "add" is the
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
307 string "<tt>__add</tt>".
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
308 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
309 the access to a metamethod does not invoke other metamethods.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
310 You can emulate how Luan queries a metamethod for an object <tt>obj</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
311 with the following code:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
312
382
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents: 380
diff changeset
313 <p><tt><pre>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
314 raw_get(get_metatable(obj) or {}, "__" .. event_name)
382
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents: 380
diff changeset
315 </pre></tt></p>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
316
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
317 <p>
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
318 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
319
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
320 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
321
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
322 <li><p><b>"add": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
323 the <tt>+</tt> operation.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
324
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
325 If any operand for an addition is a table,
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
326 Luan will try to call a metamethod.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
327 First, Luan will check the first operand (even if it is valid).
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
328 If that operand does not define a metamethod for the "<tt>__add</tt>" event,
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
329 then Luan will check the second operand.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
330 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
331 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
332 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
333 (adjusted to one value)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
334 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
335 Otherwise,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
336 it raises an error.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
337 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
338
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
339 <li><p><b>"sub": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
340 the <tt>-</tt> operation.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
341
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
342 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
343 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
344
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
345 <li><p><b>"mul": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
346 the <tt>*</tt> operation.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
347
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
348 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
349 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
350
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
351 <li><p><b>"div": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
352 the <tt>/</tt> operation.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
353
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
354 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
355 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
356
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
357 <li><p><b>"mod": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
358 the <tt>%</tt> operation.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
359
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
360 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
361 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
362
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
363 <li><p><b>"pow": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
364 the <tt>^</tt> (exponentiation) operation.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
365
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
366 Behavior similar to the "add" operation.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
367 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
368
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
369 <li><p><b>"unm": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
370 the <tt>-</tt> (unary minus) operation.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
372 Behavior similar to the "add" operation.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
373 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
374
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
375 <li><p><b>"concat": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
376 the <tt>..</tt> (concatenation) operation.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
377
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
378 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
379 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
380
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
381 <li><p><b>"len": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
382 the <tt>#</tt> (length) operation.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
383
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
384 If there is a metamethod,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
385 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
386 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
387 (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
388 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
389 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
390 then Luan uses the table length operation (see <a href="#length">The Length Operator</a>).
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
391 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
392 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
393
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
394 <li><p><b>"eq": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
395 the <tt>==</tt> (equal) operation.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
396
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
397 Behavior similar to the "add" operation,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
398 except that Luan will try a metamethod only when the values
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
399 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
400 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
401 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
402 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
403
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
404 <li><p><b>"lt": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
405 the <tt>&lt;</tt> (less than) operation.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
406
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
407 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
408 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
409 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
410
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
411 <li><p><b>"le": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
412 the <tt>&lt;=</tt> (less equal) operation.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
413
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
414 Unlike other operations,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
415 The less-equal operation can use two different events.
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
416 First, Luan looks for the "<tt>__le</tt>" metamethod in both operands,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
417 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
418 If it cannot find such a metamethod,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
419 then it will try the "<tt>__lt</tt>" event,
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
420 assuming that <tt>a &lt;= b</tt> is equivalent to <tt>not (b &lt; a)</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
421 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
422 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
423 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
424
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
425 <li><p><b>"index": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
426 The indexing access <tt>table[key]</tt>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
427
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
428 This event happens
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
429 when <tt>key</tt> is not present in <tt>table</tt>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
430 The metamethod is looked up in <tt>table</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
431
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
432
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
433 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
434 Despite the name,
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
435 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
436 If it is a function,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
437 it is called with <tt>table</tt> and <tt>key</tt> as arguments.
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
438 Otherwise
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
439 the final result is the result of indexing this metamethod object with <tt>key</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
440 (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
441 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
442 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
443
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
444 <li><p><b>"new_index": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
445 The indexing assignment <tt>table[key] = value</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
446
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
447 Like the index event,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
448 this event happens when
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
449 when <tt>key</tt> is not present in <tt>table</tt>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
450 The metamethod is looked up in <tt>table</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
451
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
452
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
453 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
454 Like with indexing,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
455 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
456 If it is a function,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
457 it is called with <tt>table</tt>, <tt>key</tt>, and <tt>value</tt> as arguments.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
458 If it is a table,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
459 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
460 (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
461 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
462
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
463
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
464 <p>
428
df95199ca4c0 rename __newindex to __new_index
Franklin Schmidt <fschmidt@gmail.com>
parents: 418
diff changeset
465 Whenever there is a "new_index" metamethod,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
466 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
467 (If necessary,
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
468 the metamethod itself can call <a href="#Luan.raw_set"><tt>raw_set</tt></a>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
469 to do the assignment.)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
470 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
471
502
d3183a330ff5 improve the __index metamethod to work with any type;
Franklin Schmidt <fschmidt@gmail.com>
parents: 495
diff changeset
472 <li><p><b>"call": </b>
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
473 The call operation <tt>func(args)</tt>.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
474
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
475 This event happens when Luan tries to call a table.
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
476 The metamethod is looked up in <tt>func</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
477 If present,
373
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
478 the metamethod is called with <tt>func</tt> as its first argument,
571057b1666b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
479 followed by the arguments of the original call (<tt>args</tt>).
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
480 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
481
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
482 </ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
483
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
486
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
487 <h3 <%=heading_options%> ><a name="gc">Garbage Collection</a></h3>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
488
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
489 <p>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
490 Luan uses Java's garbage collection.
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
491
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
492
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
493
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
494
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
495
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
496 <h2 <%=heading_options%> ><a name="lang">The Language</a></h2>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
497
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
498 <p>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
499 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
500 In other words,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
501 this section describes
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
502 which tokens are valid,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
503 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
504 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
505
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
506
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
507 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
508 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
509 in which
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
510 {<i>a</i>}&nbsp;means&nbsp;0 or more <i>a</i>'s, and
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
511 [<i>a</i>]&nbsp;means an optional <i>a</i>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
512 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
513 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
514 and other terminal symbols are shown like &lsquo;<b>=</b>&rsquo;.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
515 The complete syntax of Luan can be found in <a href="#9">&sect;9</a>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
516 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
517
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
518
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
519
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
520 <h3 <%=heading_options%> ><a name="lex">Lexical Conventions</a></h3>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
521
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
522 <p>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
523 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
524 between lexical elements (tokens),
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
525 except as delimiters between names and keywords.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
526 Luan generally considers the end of a line to be the end of a statement. This catches errors and encourages readability. The exception to this is in paranthesis ( <i>(...)</i>, <i>[...]</i>, and <i>{...}</i> ) where the end of line is treated as white space.
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
527
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
528 <p>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
529 <i>Names</i>
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
530 (also called <i>identifiers</i>)
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
531 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
532 digits, and underscores,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
533 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
534 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
535
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
536
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
537 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
538 The following <i>keywords</i> are reserved
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
539 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
540
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
541
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
542 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
543 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
544 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
545 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
546 then true until while
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
547 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
548
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
549 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
550 Luan is a case-sensitive language:
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
551 <tt>and</tt> is a reserved word, but <tt>And</tt> and <tt>AND</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
552 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
553
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
554
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
555 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
556 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
557
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
558 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
559 + - * / % ^ #
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
560 &amp; ~ | &lt;&lt; &gt;&gt; //
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
561 == ~= &lt;= &gt;= &lt; &gt; =
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 ; : , . .. ...
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
564 </pre></tt></p>
371
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 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
567 <i>Literal strings</i>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
568 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
569 and can contain the following C-like escape sequences:
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
570 '<tt>\a</tt>' (bell),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
571 '<tt>\b</tt>' (backspace),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
572 '<tt>\f</tt>' (form feed),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
573 '<tt>\n</tt>' (newline),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
574 '<tt>\r</tt>' (carriage return),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
575 '<tt>\t</tt>' (horizontal tab),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
576 '<tt>\v</tt>' (vertical tab),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
577 '<tt>\\</tt>' (backslash),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
578 '<tt>\"</tt>' (quotation mark [double quote]),
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
579 and '<tt>\'</tt>' (apostrophe [single quote]).
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
580 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
581 results in a newline in the string.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
582 The escape sequence '<tt>\z</tt>' skips the following span
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
583 of white-space characters,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
584 including line breaks;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
585 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
586 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
587 into the string contents.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
588
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
589
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
590 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
591 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
592 This can be done
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
593 with the escape sequence <tt>\x<i>XX</i></tt>,
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
594 where <i>XX</i> is a sequence of exactly two hexadecimal digits,
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
595 or with the escape sequence <tt>\<i>ddd</i></tt>,
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
596 where <i>ddd</i> is a sequence of up to three decimal digits.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
597 (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
598 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
599
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
600
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
601 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
602 Literal strings can also be defined using a long format
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
603 enclosed by <i>long brackets</i>.
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
604 We define an <i>opening long bracket of level <i>n</i></i> as an opening
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
605 square bracket followed by <i>n</i> equal signs followed by another
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
606 opening square bracket.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
607 So, an opening long bracket of level 0 is written as <tt>[[</tt>,
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
608 an opening long bracket of level 1 is written as <tt>[=[</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
609 and so on.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
610 A <i>closing long bracket</i> is defined similarly;
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
611 for instance,
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
612 a closing long bracket of level 4 is written as <tt>]====]</tt>.
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
613 A <i>long literal</i> starts with an opening long bracket of any level and
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
614 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
615 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
616 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
617 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
618 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
619 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
620 (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
621 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
622 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
623
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
624
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
625 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
626 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
627 explicitly affected by the previous rules represents itself.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
628 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
629 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
630 some control characters.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
631 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
632 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
633 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
634
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
635
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
636 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
637 For convenience,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
638 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
639 the newline is not included in the string.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
640 As an example
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
641 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
642
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
643 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
644 a = 'alo\n123"'
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
645 a = "alo\n123\""
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
646 a = '\97lo\10\04923"'
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
647 a = [[alo
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
648 123"]]
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
649 a = [==[
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
650 alo
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
651 123"]==]
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
652 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
653
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
654 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
655 A <i>numerical constant</i> (or <i>numeral</i>)
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
656 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
657 and an optional decimal exponent,
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
658 marked by a letter '<tt>e</tt>' or '<tt>E</tt>'.
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
659 Luan also accepts hexadecimal constants,
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
660 which start with <tt>0x</tt> or <tt>0X</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
661 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
662 plus an optional binary exponent,
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
663 marked by a letter '<tt>p</tt>' or '<tt>P</tt>'.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
664 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
665 denotes a float;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
666 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
667 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
668
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
669 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
670 3 345 0xff 0xBEBADA
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
671 </pre></tt></p>
382
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents: 380
diff changeset
672
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents: 380
diff changeset
673 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
674 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
675
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
676 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
677 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
678 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
679 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
680
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
681 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
682 A <i>comment</i> starts with a double hyphen (<tt>--</tt>)
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
683 anywhere outside a string.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
684 If the text immediately after <tt>--</tt> is not an opening long bracket,
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
685 the comment is a <i>short comment</i>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
686 which runs until the end of the line.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
687 Otherwise, it is a <i>long comment</i>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
688 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
689 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
690
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
691
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
692
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
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
695 <h3 <%=heading_options%> ><a name="vars">Variables</a></h3>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
696
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
697 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
698 Variables are places that store values.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
699 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
700 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
701
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
702 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
703 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
704 (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
705 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
706
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
707 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
708 var ::= Name
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
709 </pre></tt></p>
382
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents: 380
diff changeset
710
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents: 380
diff changeset
711 <p>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
712 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
713
512
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
714 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
715 Local variables are <i>lexically scoped</i>:
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
716 local variables can be freely accessed by functions
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
717 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
718
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
719
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
720 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
721 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
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 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
725
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
726 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
727 var ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo;
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
728 </pre></tt></p>
382
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents: 380
diff changeset
729
8557581740db added tutorial
Franklin Schmidt <fschmidt@gmail.com>
parents: 380
diff changeset
730 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
731 The meaning of accesses to table fields can be changed via metatables.
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
732 An access to an indexed variable <tt>t[i]</tt> is equivalent to
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
733 a call <tt>gettable_event(t,i)</tt>.
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
734 (See <a href="#meta">Metatables and Metamethods</a> for a complete description of the
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
735 <tt>gettable_event</tt> function.
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
736 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
737 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
738
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
739
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
740 <p>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
741 The syntax <tt>var.Name</tt> is just syntactic sugar for
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
742 <tt>var["Name"]</tt>:
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
743
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
744 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
745 var ::= prefixexp &lsquo;<b>.</b>&rsquo; Name
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
746 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
747
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
748 <p>
512
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
749 Global variables are not available by default. To enable global variable, you must define <tt>_ENV</tt> as a local variable whose value is a table. If <tt>_ENV</tt> is not defined, then an unrecognized variable name will produce a compile error. If <tt>_ENV</tt> is defined then an access to an unrecognized variable name will be consider a global variable. So then an acces to global variable <tt>x</tt>
380
6c6c3537035e work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 373
diff changeset
750 is equivalent to <tt>_ENV.x</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
751 Due to the way that chunks are compiled,
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
752 <tt>_ENV</tt> is never a global name (see <a href="#env">Environments</a>).
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
753
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
754
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
755
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
756
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
757
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
758 <h3 <%=heading_options%> ><a name="stmts">Statements</a></h3>
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
759
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
760 <p>
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
761 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
762 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
763 This set includes
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
764 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
765 and variable declarations.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
766
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
767
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
768
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
769 <h4 <%=heading_options%> ><a name="blocks">Blocks</a></h4>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
770
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
771 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
772 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
773 which are executed sequentially:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
774
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
775 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
776 block ::= {stat}
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
777 </pre></tt></p>
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
778
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
779 <p>
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
780 Luan has <i>empty statements</i>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
781 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
782 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
783 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
784
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
785 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
786 stat ::= &lsquo;<b>;</b>&rsquo;
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
787 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
788
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
789 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
790 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
791
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
792 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
793 stat ::= <b>do</b> block <b>end</b>
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
794 </pre></tt></p>
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
795
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
796 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
797 Explicit blocks are useful
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
798 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
799 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
800 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
801 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
802
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
803
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
804
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
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
807 <h4 <%=heading_options%> ><a name="chunks">Chunks</a></h4>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
808
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
809 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
810 The unit of compilation of Luan is called a <i>chunk</i>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
811 Syntactically,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
812 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
813
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
814 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
815 chunk ::= block
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
816 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
817
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
818 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
819 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
820 with a variable number of arguments
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
821 (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
822 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
823 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
824
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
825
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
826 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
827 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
828 To execute a chunk,
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
829 Luan first <i>loads</i> it,
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
830 compiling the chunk's code,
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
831 and then Luan executes the compiled code.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
832
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
833
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
834
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
835
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
836
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
837 <h4 <%=heading_options%> ><a name="assignment">Assignment</a></h4>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
838
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
839 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
840 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
841 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
842 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
843 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
844 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
845
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
846 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
847 stat ::= varlist &lsquo;<b>=</b>&rsquo; explist
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
848 varlist ::= var {&lsquo;<b>,</b>&rsquo; var}
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
849 explist ::= exp {&lsquo;<b>,</b>&rsquo; exp}
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
850 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
851
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
852 <p>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
853 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
854
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
855
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
856 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
857 Before the assignment,
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
858 the list of values is <i>adjusted</i> to the length of
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
859 the list of variables.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
860 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
861 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
862 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
863 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
864 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
865 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
866 before the adjustment
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
867 (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
868
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
869
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
870 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
871 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
872 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
873 Thus the code
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
874
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
875 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
876 i = 3
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
877 i, a[i] = i+1, 20
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
878 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
879
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
880 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
881 sets <tt>a[3]</tt> to 20, without affecting <tt>a[4]</tt>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
882 because the <tt>i</tt> in <tt>a[i]</tt> is evaluated (to 3)
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
883 before it is assigned&nbsp;4.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
884 Similarly, the line
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
885
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
886 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
887 x, y = y, x
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
888 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
889
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
890 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
891 exchanges the values of <tt>x</tt> and <tt>y</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
892 and
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
893
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
894 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
895 x, y, z = y, z, x
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
896 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
897
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
898 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
899 cyclically permutes the values of <tt>x</tt>, <tt>y</tt>, and <tt>z</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
900
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
901
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
902 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
903 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
904 and table fields can be changed via metatables.
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
905 An assignment to an indexed variable <tt>t[i] = val</tt> is equivalent to
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
906 <tt>settable_event(t,i,val)</tt>.
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
907 (See <a href="#meta">Metatables and Metamethods</a> for a complete description of the
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
908 <tt>settable_event</tt> function.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
909 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
910 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
911
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
912
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
913 <p>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
914 An assignment to a global name <tt>x = val</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
915 is equivalent to the assignment
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
916 <tt>_ENV.x = val</tt> (see <a href="#env">Environments</a>).
512
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
917 Global names are only available when <tt>_ENV</tt> is defined.
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
918
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
919
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
920
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
921 <h4 <%=heading_options%> ><a name="control">Control Structures</a></h4>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
922
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
923 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
924 The control structures
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
925 <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
926 familiar syntax:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
927
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
928 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
929 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
930 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
931 stat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
932 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
933
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
934 <p>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
935 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
936
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
937
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
938 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
939 The condition expression of a
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
940 control structure must be a boolean.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
941 Any other value type will produce an error.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
942 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
943
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
944
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
945 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
946 In the <b>repeat</b>&ndash;<b>until</b> loop,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
947 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
948 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
949 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
950 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
951
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
952
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
953 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
954 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
955 <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
956 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
957
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
958
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
959 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
960 stat ::= <b>break</b>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
961 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
962
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
963 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
964 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
965
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
966
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
967 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
968 The <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
969 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
970 (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
971
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
972 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
973 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
974
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
975 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
976 stat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
977 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
978
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
979
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
980
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
981
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
982 <h4 <%=heading_options%> ><a name="for">For Statement</a></h4>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
983
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
984 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
985 The <b>for</b> statement works over functions,
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
986 called <i>iterators</i>.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
987 On each iteration, the iterator function is called to produce a new value,
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
988 stopping when this new value is <b>nil</b>.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
989 The <b>for</b> loop has the following syntax:
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
990
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
991 <p><tt><pre>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
992 stat ::= <b>for</b> namelist <b>in</b> exp <b>do</b> block <b>end</b>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
993 namelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
994 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
995
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
996 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
997 A <b>for</b> statement like
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
998
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
999 <p><tt><pre>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1000 for <i>var_1</i>, &middot;&middot;&middot;, <i>var_n</i> in <i>exp</i> do <i>block</i> end
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1001 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1002
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1003 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1004 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
1005
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1006 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1007 do
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1008 local <i>f</i> = <i>exp</i>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1009 while true do
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1010 local <i>var_1</i>, &middot;&middot;&middot;, <i>var_n</i> = <i>f</i>()
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1011 if <i>var_1</i> == nil then break end
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1012 <i>block</i>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1013 end
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1014 end
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1015 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1016
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1017 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1018 Note the following:
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 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1021
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1022 <li>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1023 <tt><i>exp</i></tt> is evaluated only once.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1024 Its result is an <i>iterator</i> function.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1025 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1026
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1027 <li>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1028 <tt><i>f</i></tt> is an invisible variable.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1029 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
1030 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1031
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1032 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1033 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
1034 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1035
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1036 <li>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1037 The loop variables <tt><i>var_i</i></tt> are local to the loop;
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1038 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
1039 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
1040 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
1041 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1042
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1043 </ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1044
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1047
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1048 <h4 <%=heading_options%> ><a name="fn_stmt">Function Calls as Statements</a></h4>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1049
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1050 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1051 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
1052 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
1053
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1054 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1055 stat ::= functioncall
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1056 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1057
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1058 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1059 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
1060 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
1061
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1062
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1063
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1064 <h4 <%=heading_options%> ><a name="local_stmt">Local Declarations</a></h4>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1065
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1066 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1067 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
1068 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
1069
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1070 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1071 stat ::= <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1072 </pre></tt></p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1073
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1074 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1075 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
1076 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
1077 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
1078
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1079
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1080 <p>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1081 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
1082 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
1083
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1084
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1085 <p>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1086 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
1087
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1088
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1089 <h4 <%=heading_options%> ><a name="template_stmt">Template Statements</a></h4>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1090
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1091 <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>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1092
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1093 <p><tt><pre><%=Html.encode[[
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1094 local name = "Bob"
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1095 %>
469
Franklin Schmidt <fschmidt@gmail.com>
parents: 468
diff changeset
1096 Hello <%= name %>!
Franklin Schmidt <fschmidt@gmail.com>
parents: 468
diff changeset
1097 Bye <%= name %>.
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1098 <%
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1099 ]]%></pre></tt></p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1100
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1101 <p>is equivalent to the code:</p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1102
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1103 <p><tt><pre><%=Html.encode[[
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1104 local name = "Bob"
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1105 require("luan:Io").stdout.write( %>
469
Franklin Schmidt <fschmidt@gmail.com>
parents: 468
diff changeset
1106 Hello <%= name %>!
Franklin Schmidt <fschmidt@gmail.com>
parents: 468
diff changeset
1107 Bye <%= name %>.
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1108 <% )
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1109 ]]%></pre></tt></p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1110
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1111
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1112
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1113 <h3 <%=heading_options%> ><a name="expressions">Expressions</a></h3>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1114
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1115 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1116 The basic expressions in Luan are the following:
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1117
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1118 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1119 exp ::= prefixexp
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1120 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
1121 exp ::= Numeral
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1122 exp ::= LiteralString
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1123 exp ::= functiondef
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1124 exp ::= tableconstructor
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1125 exp ::= &lsquo;<b>...</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1126 exp ::= exp binop exp
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1127 exp ::= unop exp
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1128 prefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1129 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1130
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1131 <p>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1132 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
1133 variables are explained in <a href="#vars">Variables</a>;
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1134 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
1135 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
1136 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
1137 Vararg expressions,
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1138 denoted by three dots ('<tt>...</tt>'), can only be used when
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1139 directly inside a vararg function;
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1140 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
1141
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1142
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1143 <p>
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1144 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
1145 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
1146 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
1147 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
1148 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
1149 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
1150
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1151
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1152 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1153 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
1154 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
1155 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
1156 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
1157 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
1158 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
1159 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
1160 (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
1161 In all other contexts,
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1162 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
1163 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
1164 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
1165
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1166
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1167 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1168 Here are some examples:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1169
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1170 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1171 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
1172 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
1173 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
1174 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
1175 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
1176 -- 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
1177 -- 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
1178
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1179 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
1180 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
1181 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
1182 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
1183 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
1184 {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
1185 {...} -- 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
1186 {f(), nil} -- f() is adjusted to 1 result
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1187 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1188
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1189 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1190 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
1191 Thus,
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1192 <tt>(f(x,y,z))</tt> is always a single value,
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1193 even if <tt>f</tt> returns several values.
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1194 (The value of <tt>(f(x,y,z))</tt> is the first value returned by <tt>f</tt>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1195 or <b>nil</b> if <tt>f</tt> does not return any values.)
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1196
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1197
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1198
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1199 <h4 <%=heading_options%> ><a name="arithmetic">Arithmetic Operators</a></h4>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1200
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1201 <p>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1202 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
1203
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1204 <ul>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1205 <li><b><tt>+</tt>: </b>addition</li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1206 <li><b><tt>-</tt>: </b>subtraction</li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1207 <li><b><tt>*</tt>: </b>multiplication</li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1208 <li><b><tt>/</tt>: </b>division</li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1209 <li><b><tt>%</tt>: </b>modulo</li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1210 <li><b><tt>^</tt>: </b>exponentiation</li>
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1211 <li><b><tt>-</tt>: </b>unary minus</li>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1212 </ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1213
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1214 <p>
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1215 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
1216
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1217 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1218 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
1219 that rounds the quotient towards minus infinite (floor division).
395
a7cb58532846 work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 391
diff changeset
1220 (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
1221
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1222
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1223
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1224 <h4 <%=heading_options%> ><a name="conversions">Coercions and Conversions</a></h4>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1225
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1226 <p>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1227 Luan generally avoids automatic conversions.
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1228 String concatenation automatically converts all of its arguments to strings.
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1229
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1230 <p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1231 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
1232
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1233
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1234
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1235
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1236 <h4 <%=heading_options%> ><a name="relational">Relational Operators</a></h4>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1237
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1238 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1239 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
1240
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1241 <ul>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1242 <li><b><tt>==</tt>: </b>equality</li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1243 <li><b><tt>~=</tt>: </b>inequality</li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1244 <li><b><tt>&lt;</tt>: </b>less than</li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1245 <li><b><tt>&gt;</tt>: </b>greater than</li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1246 <li><b><tt>&lt;=</tt>: </b>less or equal</li>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1247 <li><b><tt>&gt;=</tt>: </b>greater or equal</li>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1248 </ul><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1249 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
1250
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1251
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1252 <p>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1253 Equality (<tt>==</tt>) first compares the type of its operands.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1254 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
1255 Otherwise, the values of the operands are compared.
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1256 Strings, numbers, and binary values are compared in the obvious way (by value).
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1257
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1258 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1259 Tables
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1260 are compared by reference:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1261 two objects are considered equal only if they are the same object.
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1262 Every time you create a new table,
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1263 it is different from any previously existing table.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1264 Closures are also compared by reference.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1265
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1266 <p>
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1267 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
1268 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
1269
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1270 <p>
513
0dfc01d8d42d rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents: 512
diff changeset
1271 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)"><tt>equals</tt></a> method.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1272
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1273 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1274 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
1275 or vice versa.
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1276 Thus, <tt>"0"==0</tt> evaluates to <b>false</b>,
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1277 and <tt>t[0]</tt> and <tt>t["0"]</tt> denote different
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1278 entries in a table.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1279
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1280
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1281 <p>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1282 The operator <tt>~=</tt> is exactly the negation of equality (<tt>==</tt>).
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1283
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1284
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1285 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1286 The order operators work as follows.
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1287
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1288 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
1289 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
1290 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
1291 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
1292 then their values are compared according to the current locale.
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1293 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
1294 metamethod (see <a href="#meta">Metatables and Metamethods</a>).
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1295 A comparison <tt>a &gt; b</tt> is translated to <tt>b &lt; a</tt>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1296 and <tt>a &gt;= b</tt> is translated to <tt>b &lt;= a</tt>.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1297
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1298
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1299
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1300
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1301
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1302 <h4 <%=heading_options%> ><a name="logical_ops">Logical Operators</a></h4>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1303
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1304 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1305 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
1306 <b>and</b>, <b>or</b>, and <b>not</b>.
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1307 The <b>and</b> and <b>or</b> operators consider both <b>false</b> and <b>nil</b> as false
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1308 and anything else as true.
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1309 Like the control structures (see <a href="#control">Control Structures</a>),
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1310 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
1311
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1312 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1313 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
1314 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
1315 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
1316 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
1317 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
1318 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
1319 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
1320 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
1321 that is,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1322 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
1323 Here are some examples:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1324
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1325 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1326 10 or 20 --&gt; 10
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1327 10 or error() --&gt; 10
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1328 nil or "a" --&gt; "a"
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1329 nil and 10 --&gt; nil
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1330 false and error() --&gt; false
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1331 false and nil --&gt; false
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1332 false or nil --&gt; nil
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1333 10 and 20 --&gt; 20
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1334 </pre></tt></p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1335
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1336 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1337 (In this manual,
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1338 <tt>--&gt;</tt> indicates the result of the preceding expression.)
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1339
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1340
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1341
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1342 <h4 <%=heading_options%> ><a name="concatenation">Concatenation</a></h4>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1343
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1344 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1345 The string concatenation operator in Luan is
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1346 denoted by two dots ('<tt>..</tt>').
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1347 All operands are converted to strings.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1348
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1349
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1350
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1351 <h4 <%=heading_options%> ><a name="length">The Length Operator</a></h4>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1352
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1353 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1354 The length operator is denoted by the unary prefix operator <tt>#</tt>.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1355 The length of a string is its number of characters.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1356 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
1357
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1358
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1359 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1360 A program can modify the behavior of the length operator for
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1361 any table through the <tt>__len</tt> metamethod (see <a href="#meta">Metatables and Metamethods</a>).
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1362
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1363
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1364 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1365 Unless a <tt>__len</tt> metamethod is given,
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1366 the length of a table <tt>t</tt> is defined
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1367 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
1368 that is,
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1369 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
1370 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
1371 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
1372 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
1373
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1374 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1375 {10, 20, nil, 40}
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1376 </pre></tt></p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1377
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1378 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1379 has a length of <tt>2</tt>, because that is the last key in sequence.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1380
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1381
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1382
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1383
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1384
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1385 <h4 <%=heading_options%> ><a name="precedence">Precedence</a></h4>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1386
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1387 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1388 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
1389 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
1390
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1391 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1392 or
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1393 and
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1394 &lt; &gt; &lt;= &gt;= ~= ==
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1395 ..
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1396 + -
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1397 * / %
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1398 unary operators (not # -)
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1399 ^
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1400 </pre></tt></p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1401
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1402 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1403 As usual,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1404 you can use parentheses to change the precedences of an expression.
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1405 The concatenation ('<tt>..</tt>') and exponentiation ('<tt>^</tt>')
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1406 operators are right associative.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1407 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
1408
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1409
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1410
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
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1413 <h4 <%=heading_options%> ><a name="constructors">Table Constructors</a></h4>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1414
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1415 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1416 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
1417 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
1418 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
1419 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
1420 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
1421
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1422 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1423 tableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1424 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
1425 field ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1426 fieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1427 </pre></tt></p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1428
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1429 <p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1430 Each field of the form <tt>[exp1] = exp2</tt> adds to the new table an entry
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1431 with key <tt>exp1</tt> and value <tt>exp2</tt>.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1432 A field of the form <tt>name = exp</tt> is equivalent to
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1433 <tt>["name"] = exp</tt>.
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1434 Finally, fields of the form <tt>exp</tt> are equivalent to
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1435 <tt>[i] = exp</tt>, where <tt>i</tt> are consecutive integers
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1436 starting with 1.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1437 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
1438 For example,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1439
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1440 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1441 a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1442 </pre></tt></p>
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1443
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1444 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1445 is equivalent to
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1446
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1447 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1448 do
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1449 local t = {}
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1450 t[f(1)] = g
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1451 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
1452 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
1453 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
1454 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
1455 t[30] = 23
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1456 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
1457 a = t
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1458 end
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1459 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1460
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1461 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1462 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
1463 (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
1464
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1465
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1466 <p>
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 395
diff changeset
1467 If the last field in the list has the form <tt>exp</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1468 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
1469 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
1470 (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
1471
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1472
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1473 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1474 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
1475 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
1476
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1477
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1478
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
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1481 <h4 <%=heading_options%> ><a name="fn_calls">Function Calls</a></h4>
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1482
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1483 <p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1484 A function call in Luan has the following syntax:
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1485
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1486 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1487 functioncall ::= prefixexp args
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1488 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1489
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1490 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1491 In a function call,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1492 first prefixexp and args are evaluated.
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1493 If the value of prefixexp has type <i>function</i>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1494 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
1495 with the given arguments.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1496 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
1497 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
1498 followed by the original call arguments
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1499 (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
1500
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1501
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1502 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1503 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
1504
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1505 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1506 args ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1507 args ::= tableconstructor
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1508 args ::= LiteralString
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1509 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1510
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1511 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1512 All argument expressions are evaluated before the call.
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1513 A call of the form <tt>f{<i>fields</i>}</tt> is
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1514 syntactic sugar for <tt>f({<i>fields</i>})</tt>;
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1515 that is, the argument list is a single new table.
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1516 A call of the form <tt>f'<i>string</i>'</tt>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1517 (or <tt>f"<i>string</i>"</tt> or <tt>f[[<i>string</i>]]</tt>)
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1518 is syntactic sugar for <tt>f('<i>string</i>')</tt>;
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1519 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
1520
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1521
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1522 <p>
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1523 A call of the form <tt>return <i>functioncall</i></tt> is called
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1524 a <i>tail call</i>.
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1525 Luan implements <i>proper tail calls</i>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1526 (or <i>proper tail recursion</i>):
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1527 in a tail call,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1528 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
1529 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
1530 a program can execute.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1531 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
1532 calling function.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1533 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
1534 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
1535 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
1536 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
1537 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
1538
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1539 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1540 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
1541 return 2 * f(x)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1542 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
1543 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
1544 return x or f(x) -- results adjusted to 1
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1545 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1546
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1547
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1548
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1549
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1550 <h4 <%=heading_options%> ><a name="fn_def">Function Definitions</a></h4>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1551
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1552 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1553 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
1554
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1555 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1556 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
1557 funcbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1558 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1559
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1560 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1561 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
1562
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1563 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1564 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
1565 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
1566 funcname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1567 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1568
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1569 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1570 The statement
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1571
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1572 <p><tt><pre>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1573 function f () <i>body</i> end
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1574 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1575
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1576 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1577 translates to
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1578
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1579 <p><tt><pre>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1580 f = function () <i>body</i> end
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1581 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1582
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1583 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1584 The statement
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1585
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1586 <p><tt><pre>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1587 function t.a.b.c.f () <i>body</i> end
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1588 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1589
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1590 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1591 translates to
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1592
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1593 <p><tt><pre>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1594 t.a.b.c.f = function () <i>body</i> end
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1595 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1596
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1597 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1598 The statement
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1599
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1600 <p><tt><pre>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1601 local function f () <i>body</i> end
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1602 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1603
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1604 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1605 translates to
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1606
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1607 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1608 local f; f = function () <em>body</em> end
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1609 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1610
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1611 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1612 not to
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1613
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1614 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1615 local f = function () <em>body</em> end
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1616 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1617
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1618 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1619 (This only makes a difference when the body of the function
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1620 contains references to <tt>f</tt>.)
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1621
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1622
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1623 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1624 A function definition is an executable expression,
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1625 whose value has type <i>function</i>.
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1626 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
1627 all its function bodies are precompiled too.
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1628 Then, whenever Luan executes the function definition,
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1629 the function is <i>instantiated</i> (or <i>closed</i>).
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1630 This function instance (or <i>closure</i>)
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1631 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
1632
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1633
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1634 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1635 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
1636 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
1637
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1638 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1639 parlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1640 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1641
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1642 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1643 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
1644 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
1645 the length of the list of parameters,
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1646 unless the function is a <i>vararg function</i>,
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1647 which is indicated by three dots ('<tt>...</tt>')
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1648 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
1649 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
1650 instead, it collects all extra arguments and supplies them
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1651 to the function through a <i>vararg expression</i>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1652 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
1653 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
1654 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
1655 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
1656 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
1657 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
1658 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
1659 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
1660 (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
1661
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1662
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1663 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1664 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
1665
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1666 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1667 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
1668 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
1669 function r() return 1,2,3 end
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1670 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1671
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1672 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1673 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
1674 to the vararg expression:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1675
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1676 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1677 CALL PARAMETERS
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1678
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1679 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
1680 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
1681 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
1682 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
1683 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
1684
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1685 g(3) a=3, b=nil, ... --&gt; (nothing)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1686 g(3, 4) a=3, b=4, ... --&gt; (nothing)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1687 g(3, 4, 5, 8) a=3, b=4, ... --&gt; 5 8
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1688 g(5, r()) a=5, b=1, ... --&gt; 2 3
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1689 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1690
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1691 <p>
464
eddf7c73373b fix references in the manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 429
diff changeset
1692 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
1693 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
1694 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
1695 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
1696
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1697
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1698 <h4 <%=heading_options%> ><a name="template_expr">Template Expressions</a></h4>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1699
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1700 <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>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1701
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1702 <p><tt><pre><%=Html.encode[[
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1703 local name = "Bob"
469
Franklin Schmidt <fschmidt@gmail.com>
parents: 468
diff changeset
1704 write( %>Hello <%= name %>!<% )
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1705 ]]%></pre></tt></p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1706
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1707 <p>This is equivalent to the code:</p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1708
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1709 <p><tt><pre>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1710 local name = "Bob"
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1711 write( "Hello ", name, "!" )
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1712 </pre></tt></p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1713
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1714 <p>The strings in template expressions may be multiple lines.</p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
1715
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1716
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1717
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1718 <h3 <%=heading_options%> ><a name="visibility">Visibility Rules</a></h3>
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1719
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1720 <p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1721 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
1722 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
1723 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
1724 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
1725 Consider the following example:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1726
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1727 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1728 x = 10 -- global variable
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1729 do -- new block
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1730 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
1731 print(x) --&gt; 10
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1732 x = x+1
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1733 do -- another block
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1734 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
1735 print(x) --&gt; 12
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1736 end
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1737 print(x) --&gt; 11
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1738 end
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1739 print(x) --&gt; 10 (the global one)
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1740 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1741
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1742 <p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1743 Notice that, in a declaration like <tt>local x = x</tt>,
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1744 the new <tt>x</tt> being declared is not in scope yet,
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1745 and so the second <tt>x</tt> refers to the outside variable.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1746
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1747
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1748 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1749 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
1750 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
1751 defined inside their scope.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1752 A local variable used by an inner function is called
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1753 an <i>upvalue</i>, or <i>external local variable</i>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1754 inside the inner function.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1755
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1756
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1757 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1758 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
1759 defines new local variables.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1760 Consider the following example:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1761
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1762 <p><tt><pre>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1763 a = {}
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1764 local x = 20
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1765 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
1766 local y = 0
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1767 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
1768 end
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1769 </pre></tt></p>
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1770
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1771 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1772 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
1773 (that is, ten instances of the anonymous function).
417
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1774 Each of these closures uses a different <tt>y</tt> variable,
a40e99cf0b0b work on manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
1775 while all of them share the same <tt>x</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1776
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1777
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1778
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1779
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1780
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1781 <h2 <%=heading_options%> ><a name="libs">Standard Libraries</a></h2>
468
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1782
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1783 <p>
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1784 The standard Luan libraries provide useful functions
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1785 that are implemented both in Java and in Luan itself.
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1786 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
1787 Some of these functions provide essential services to the language
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
1788 (e.g., <a href="#Luan.type"><tt>type</tt></a> and <a href="#Luan.get_metatable"><tt>get_metatable</tt></a>);
468
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1789 others provide access to "outside" services (e.g., I/O).
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1790
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1791
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1792 <h3 <%=heading_options%> ><a name="default_lib">Default Environment</a></h3>
468
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1793
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1794 <p>
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1795 These are provided by default as local variables for any Luan code as described in <a href="#env">Environments</a>.
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
1796
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1797
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1798 <h4 <%=heading_options%> ><a name="require"><tt>java ()</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1799
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1800 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1801 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.
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1802
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1803
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1804 <h4 <%=heading_options%> ><a name="require"><tt>require (mod_uri)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1805
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1806 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1807 Example use:
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1808
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1809 <p><tt><pre>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1810 local Table = require "luan:Table"
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1811 </pre></tt></p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1812
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1813 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1814 Could be defined as:
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1815
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1816 <p><tt><pre>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1817 local function require(mod_name)
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
1818 return <a href="#Package.load">Package.load</a>(mod_name) or <a href="#Luan.error">Luan.error</a>("module '"..mod_name.."' not found")
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1819 end
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1820 </pre></tt></p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1821
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1822
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1823 <h3 <%=heading_options%> ><a name="luan_lib">Basic Functions</a></h3>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1824
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1825 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1826 Include this library by:
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1827
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1828 <p><tt><pre>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1829 local Luan = require "luan:Luan"
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1830 </pre></tt></p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1831
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
1832 <p>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1833 The basic library provides basic functions to Luan that don't depend on other libaries.
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1834
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1835
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1836 <h4 <%=heading_options%> ><a name="Luan.assert"><tt>Luan.assert (v [, message])</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1837
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1838 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1839 Could be defined as:
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1840
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1841 <p><tt><pre>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1842 function Luan.assert(v,message)
472
f4aca5a5346a minor documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 470
diff changeset
1843 return v or <a href="#Luan.error">Luan.error</a>(message or "assertion failed!")
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1844 end
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1845 </pre></tt></p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1846
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1847
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1848 <h4 <%=heading_options%> ><a name="Luan.assert_binary"><tt>Luan.assert_binary (v)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1849
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1850 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1851 Could be defined as:
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1852
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1853 <p><tt><pre>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1854 function Luan.assert_binary(v)
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1855 local v_type = Luan.type(v)
472
f4aca5a5346a minor documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 470
diff changeset
1856 return v_type == "binary" and v or <a href="#Luan.error">Luan.error</a>("bad argument #1 (binary expected, got "..v_type..")")
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1857 end
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1858 </pre></tt></p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1859
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1860
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1861 <h4 <%=heading_options%> ><a name="Luan.assert_boolean"><tt>Luan.assert_boolean (v)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1862
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1863 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1864 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>boolean</tt>.
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1865
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1866
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1867 <h4 <%=heading_options%> ><a name="Luan.assert_integer"><tt>Luan.assert_integer (v)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1868
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1869 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1870 Asserts that <tt>v</tt> can be converted to Java type <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html">Integer</a> and returns an Integer.
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1871
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1872
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1873 <h4 <%=heading_options%> ><a name="Luan.assert_long"><tt>Luan.assert_long (v)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1874
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1875 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1876 Asserts that <tt>v</tt> can be converted to Java type <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html">Long</a> and returns a Long.
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1877
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1878
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1879 <h4 <%=heading_options%> ><a name="Luan.assert_number"><tt>Luan.assert_number (v)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1880
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1881 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1882 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>number</tt>.
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1883
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1884
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1885 <h4 <%=heading_options%> ><a name="Luan.assert_string"><tt>Luan.assert_string (v)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1886
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1887 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1888 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>string</tt>.
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1889
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1890
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1891 <h4 <%=heading_options%> ><a name="Luan.assert_table"><tt>Luan.assert_table (v)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1892
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1893 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1894 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>table</tt>.
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1895
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1896
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1897 <h4 <%=heading_options%> ><a name="Luan.do_file"><tt>Luan.do_file ([uri])</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1898
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1899 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1900 Could be defined as:
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1901
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1902 <p><tt><pre>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1903 function Luan.do_file(uri)
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1904 return <a href="#Luan.load_file">Luan.load_file</a>(uri)()
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1905 end
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1906 </pre></tt></p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1907
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1908
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1909
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1910 <h4 <%=heading_options%> ><a name="Luan.error"><tt>Luan.error (message)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1911
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1912 <p>
482
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1913 Throws an error containing the message.
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1914
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1915 <p>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1916 Could be defined as:
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1917
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1918 <p><tt><pre>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1919 function Luan.error(message)
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1920 <a href="#Luan.new_error">Luan.new_error</a>(message).throw()
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1921 end
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1922 </pre></tt></p>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
1923
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1924
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1925
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1926 <h4 <%=heading_options%> ><a name="Luan.get_metatable"><tt>Luan.get_metatable (table)</tt></a></h4>
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1927
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1928 <p>
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1929 If <tt>table</tt> does not have a metatable, returns <b>nil</b>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1930 Otherwise,
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1931 if the table's metatable has a <tt>"__metatable"</tt> field,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1932 returns the associated value.
470
5627eb637eb4 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 469
diff changeset
1933 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
1934
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1935
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1936 <h4 <%=heading_options%> ><a name="Luan.ipairs"><tt>Luan.ipairs (t)</tt></a></h4>
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1937
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1938 <p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1939 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
1940 so that the construction
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1941
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1942 <p><tt><pre>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1943 for i,v in ipairs(t) do <i>body</i> end
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1944 </pre></tt></p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1945
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1946 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1947 will iterate over the key&ndash;value pairs
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1948 (<tt>1,t[1]</tt>), (<tt>2,t[2]</tt>), ...,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1949 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
1950
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1951 <p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1952 Could be defined as:
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1953
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1954 <p><tt><pre>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1955 function Luan.ipairs(t)
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1956 local i = 0
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1957 return function()
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1958 if i < #t then
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1959 i = i + 1
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1960 return i, t[i]
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1961 end
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1962 end
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1963 end
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1964 </pre></tt></p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1965
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1966
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1967
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1968 <h4 <%=heading_options%> ><a name="Luan.load"><tt>Luan.load (text, source_name [env, [, allow_expression]])</tt></a></h4>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1969
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1970 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1971 Loads a chunk.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1972
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1973 <p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1974 The <tt>text</tt> is compiled.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1975 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
1976 returns the compiled chunk as a function;
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1977 otherwise, throws an error.
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1978
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1979 <p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1980 The <tt>source_name</tt> parameter is a string saying where the text came from. It is used to produce error messages.
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1981
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1982 <p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1983 If the <tt>env</tt> parameter is supplied, it becomes the <tt>_ENV</tt> of the chunk.
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1984
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1985 <p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1986 If the <tt>allow_expression</tt> parameter is <tt>true</tt> then the entire text can be nothing more than an expression in which case the chunk returns the value of this expression.
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1987
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1988
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
1989 <h4 <%=heading_options%> ><a name="Luan.load_file"><tt>Luan.load_file (file_uri [, add_extension])</tt></a></h4>
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1990
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1991 <p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1992 Similar to <a href="#Luan.load"><tt>load</tt></a>,
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1993 but gets the chunk from file <tt>file_uri</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1994 or from the standard input,
474
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1995 if no file uri is given.
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1996
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1997 <p>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1998 Could be defined as:
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
1999
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
2000 <p><tt><pre>
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
2001 function Luan.load_file(file_uri,add_extension)
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
2002 file_uri = file_uri or "stdin:"
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
2003 local f = Io.uri(file_uri,add_extension)
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
2004 f.exists() or <a href="#Luan.error">Luan.error</a>("file '"..file_uri.."' not found")
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
2005 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri )
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
2006 end
00646edc9d92 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 472
diff changeset
2007 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2008
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2009
482
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2010 <h4 <%=heading_options%> ><a name="Luan.new_error"><tt>Luan.new_error (message)</tt></a></h4>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2011
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2012 <p>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2013 Creates a new error table containing the message assigned to "<tt>message</tt>". The error table also contains a <tt>throw</tt> function which throws the error. The table also contains a list of stack trace elements where each stack trace element is a table containing "<tt>source</tt>", "<tt>line</tt>", and possible "<tt>call_to</tt>". The table also has a metatable containing "<tt>__to_string</tt>" to render the error.
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2014
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2015 <p>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2016 To print the current stack trace, you could do:
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2017
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2018 <p><tt><pre>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2019 Io.print( Luan.new_error "stack" )
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2020 </pre></tt></p>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2021
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2022
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2023 <h4 <%=heading_options%> ><a name="Luan.pairs"><tt>Luan.pairs (t)</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2024
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2025 <p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2026 If <tt>t</tt> has a metamethod <tt>__pairs</tt>,
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2027 calls it with <tt>t</tt> as argument and returns the
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2028 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
2029
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2030
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2031 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2032 Otherwise,
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2033 returns a function
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2034 so that the construction
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2035
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2036 <p><tt><pre>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2037 for k,v in pairs(t) do <i>body</i> end
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2038 </pre></tt></p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2039
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2040 <p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2041 will iterate over all key&ndash;value pairs of table <tt>t</tt>.
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2042
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2043
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2044
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2045 <h4 <%=heading_options%> ><a name="Luan.pcall"><tt>Luan.pcall (f [, arg1, &middot;&middot;&middot;])</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2046
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2047 <p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2048 Calls function <tt>f</tt> with
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2049 the given arguments in <i>protected mode</i>.
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2050 This means that any error inside&nbsp;<tt>f</tt> is not propagated;
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2051 instead, <tt>pcall</tt> catches the error
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2052 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
2053 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
2054 which is true if the call succeeds without errors.
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2055 In such case, <tt>pcall</tt> also returns all results from the call,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2056 after this first result.
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2057 In case of any error, <tt>pcall</tt> returns <b>false</b> plus the error.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2058
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2059
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2060
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2063 <hr><h3><a name="pdf-print"><code>print (&middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2064 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
2065 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
2066 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
2067 <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
2068 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
2069 for instance for debugging.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2070 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
2071 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
2072
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2073
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2074
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2075 <h4 <%=heading_options%> ><a name="Luan.range"><tt>Luan.range (start, stop [, step])</tt></a></h4>
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2076
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2077 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2078 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.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2079
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2080 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2081 Example use:
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2082
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2083 <p><tt><pre>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2084 for i in range(1,10) do
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2085 Io.print("count up:",i)
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2086 end
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2087 for i in range(10,0,-1) do
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2088 Io.print("count down:",i)
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2089 end
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2090 </pre></tt></p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2091
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2092 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2093 Could be defined as:
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2094
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2095 <p><tt><pre>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2096 function Luan.range(start, stop, step)
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2097 step = step or 1
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
2098 step == 0 and <a href="#Luan.error">Luan.error</a> "bad argument #3 (step may not be zero)"
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2099 local i = start
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2100 return function()
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2101 if step > 0 and i <= stop or step < 0 and i >= stop then
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2102 local rtn = i
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2103 i = i + step
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2104 return rtn
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2105 end
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2106 end
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2107 end
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2108 </pre></tt></p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2109
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2110
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2111
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2112 <h4 <%=heading_options%> ><a name="Luan.raw_equal"><tt>Luan.raw_equal (v1, v2)</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2113
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2114 <p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2115 Checks whether <tt>v1</tt> is equal to <tt>v2</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2116 without invoking any metamethod.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2117 Returns a boolean.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2118
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2119
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2120
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2121 <h4 <%=heading_options%> ><a name="Luan.raw_get"><tt>Luan.raw_get (table, index)</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2122
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2123 <p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2124 Gets the real value of <tt>table[index]</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2125 without invoking any metamethod.
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2126 <tt>table</tt> must be a table;
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2127 <tt>index</tt> may be any value.
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2128
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2129
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2130
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2131 <h4 <%=heading_options%> ><a name="Luan.raw_len"><tt>Luan.raw_len (v)</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2132
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2133 <p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2134 Returns the length of the object <tt>v</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2135 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
2136 without invoking any metamethod.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2137 Returns an integer.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2138
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2139
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2140
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2141 <h4 <%=heading_options%> ><a name="Luan.raw_set"><tt>Luan.raw_set (table, index, value)</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2142
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2143 <p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2144 Sets the real value of <tt>table[index]</tt> to <tt>value</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2145 without invoking any metamethod.
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2146 <tt>table</tt> must be a table,
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2147 <tt>index</tt> any value different from <b>nil</b>,
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2148 and <tt>value</tt> any Lua value.
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2149
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2150
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2151 <h4 <%=heading_options%> ><a name="Luan.set_metatable"><tt>Luan.set_metatable (table, metatable)</tt></a></h4>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2152
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2153 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2154 Sets the metatable for the given table.
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2155 If <tt>metatable</tt> is <b>nil</b>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2156 removes the metatable of the given table.
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2157 If the original metatable has a <tt>"__metatable"</tt> field,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2158 raises an error.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2159
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2160
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2161
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2162 <h4 <%=heading_options%> ><a name="Luan.to_string"><tt>Luan.to_string (v)</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2163
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2164 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2165 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
2166 converts it to a string in a human-readable format.
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2167
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2168 <p>
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2169 If the metatable of <tt>v</tt> has a <tt>"__to_string"</tt> field,
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2170 then <tt>to_string</tt> calls the corresponding value
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2171 with <tt>v</tt> as argument,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2172 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
2173
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2174
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2175
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2176 <h4 <%=heading_options%> ><a name="Luan.try"><tt>Luan.try (t)</tt></a></h4>
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2177
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2178 <p>
490
ddee9f5167d8 minor documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 482
diff changeset
2179 Implements try-catch as found in other languages where each block is in table <tt>t</tt>. <tt>t[1]</tt> is the "try" block. The <tt>t.catch</tt> and <tt>t.finally</tt> blocks are optional. Returns the result of the "try" block or the "catch" block.
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2180
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2181 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2182 Example use:
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2183
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2184 <p><tt><pre>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2185 try {
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2186 function()
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2187 a_dangerous_fn()
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2188 end;
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2189 catch = function(e)
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2190 -- handle error
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2191 end;
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2192 finally = function()
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2193 -- clean up
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2194 end;
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2195 }
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2196 </pre></tt></p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2197
482
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2198 <p>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2199 Could be defined as:
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2200
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2201 <p><tt><pre>
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2202 function Luan.try(t)
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2203 local r = { <a href="#Luan.pcall">Luan.pcall</a>(t[1]) }
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2204 if r[1] then
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2205 Table.remove(r,1)
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2206 elseif t.catch ~= nil then
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2207 r = { t.catch(r[2]) }
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2208 else
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2209 t.finally and t.finally()
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2210 r[2].throw()
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2211 end
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2212 t.finally and t.finally()
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2213 return Table.unpack(r)
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2214 end
7e9fcfbf22ec documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 479
diff changeset
2215 </pre></tt></p>
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2216
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2217
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2218 <h4 <%=heading_options%> ><a name="Luan.type"><tt>Luan.type (v)</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2219
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2220 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2221 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
2222 The possible results of this function are
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2223 "<tt>nil</tt>" (a string, not the value <b>nil</b>),
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2224 "<tt>number</tt>",
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2225 "<tt>string</tt>",
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2226 "<tt>binary</tt>",
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2227 "<tt>boolean</tt>",
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2228 "<tt>table</tt>",
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2229 "<tt>function</tt>",
513
0dfc01d8d42d rename type "userdata" to "java"
Franklin Schmidt <fschmidt@gmail.com>
parents: 512
diff changeset
2230 and "<tt>java</tt>".
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2231
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2232
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2233 <h4 <%=heading_options%> ><a name="Luan.values"><tt>Luan.values (&middot;&middot;&middot;)</tt></a></h4>
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2234
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2235 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2236 Returns a function so that the construction
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2237
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2238 <p><tt><pre>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2239 for v in Luan.values(&middot;&middot;&middot;) do <i>body</i> end
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2240 </pre></tt></p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2241
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2242 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2243 will iterate over all values of <tt>&middot;&middot;&middot;</tt>.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2244
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2245
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2246
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2247 <h4 <%=heading_options%> ><a name="Luan.VERSION"><tt>Luan.VERSION</tt></a></h4>
475
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2248
7ac0891718eb documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 474
diff changeset
2249 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2250 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
2251 holds a string containing the current interpreter version.
478
eb6d90fb0b5c documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 476
diff changeset
2252 The current value of this variable is "<tt><%=Luan.VERSION%></tt>".
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2253
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2254
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2255
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2256
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2257
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2258
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2259 <h3 <%=heading_options%> ><a name="package_lib">Modules</a></h3>
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2260
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2261 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2262 Include this library by:
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2263
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2264 <p><tt><pre>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2265 local Package = require "luan:Package"
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2266 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2267
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2268 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2269 The package library provides basic
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2270 facilities for loading modules in Luan.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2271
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2272
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2273 <h4 <%=heading_options%> ><a name="Package.load"><tt>Package.load (mod_uri)</tt></a></h4>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2274
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2275 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2276 Loads the given module.
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2277 The function starts by looking into the <a href="#Package.loaded"><tt>Package.loaded</tt></a> table
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2278 to determine whether <tt>mod_uri</tt> is already loaded.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2279 If it is, then <tt>Package.load</tt> returns the value stored
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2280 at <tt>Package.loaded[mod_uri]</tt>.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2281 Otherwise, it tries to load a new value for the module.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2282
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2283 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2284 To load a new value, <tt>Package.load</tt> first checks if <tt>mod_uri</tt> starts with "<b>java:</b>". If yes, then this is a Java class which is loaded by special Java code.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2285
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2286 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2287 If <tt>mod_uri</tt> is not a Java class, then <tt>Package.load</tt> tries to read the text of the file referred to by <tt>mod_uri</tt> (using <tt>add_extension</tt>=true). If the file doesn't exist, then <tt>Package.load</tt> returns <b>nil</b>. If the file exists, then its content is compiled into a chunk calling <a href="#Luan.load"><tt>Luan.load</tt></a> and passing in an empty table as the <tt>env</tt> value. This chunk is run passing in <tt>mod_uri</tt> as an argument. If the chunk returns a value other than <b>nil</b>, then that value is the value of this module. Otherwise the <tt>env</tt> that was passed in is the value of this module.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2288
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2289 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2290 If a new value for the module successful loaded, then it is stored in <tt>Package.loaded[mod_uri]</tt>. The value is returned.
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2291
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2292
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2293
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2294
479
1285c52ea9d4 add manual heading_options
Franklin Schmidt <fschmidt@gmail.com>
parents: 478
diff changeset
2295 <h4 <%=heading_options%> ><a name="Package.loaded"><tt>Package.loaded</tt></a></h4>
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2296
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2297
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2298 <p>
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2299 A table used by <a href="#Package.load"><tt>Package.load</tt></a> to control which
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2300 modules are already loaded.
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2301 When you load a module <tt>mod_uri</tt> and
553
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
2302 <tt>Package.loaded[mod_uri]</tt> is not <b>nil</b>,
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2303 <a href="#Package.load"><tt>Package.load</tt></a> simply returns the value stored there.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2304
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2305
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2306 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2307 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
2308 assignments to this variable do not change the
476
cd22e4694ea3 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 475
diff changeset
2309 table used by <a href="#Package.load"><tt>Package.load</tt></a>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2310
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2311
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2312
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2313
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2314
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2315
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2316 <h3 <%=heading_options%> ><a name="string_lib">String Manipulation</a></h3>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2317
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2318 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2319 Include this library by:
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><tt><pre>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2322 local String = require "luan:String"
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2323 </pre></tt></p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2324
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2325 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2326 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
2327 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
2328 When indexing a string in Luan, the first character is at position&nbsp;1
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2329 (not at&nbsp;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
2330 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
2331 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
2332 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
2333
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2334
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2335
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2336 <h4 <%=heading_options%> ><a name="String.char"><tt>String.char (&middot;&middot;&middot;)</tt></a></h4>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2337
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2338 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2339 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
2340 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
2341 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
2342 to its corresponding argument.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2343
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2344
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2345 <h4 <%=heading_options%> ><a name="String.concat"><tt>String.concat (&middot;&middot;&middot;)</tt></a></h4>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2346
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2347 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2348 Concatenates the <a href="#Luan.to_string"><tt>to_string</tt></a> value of all arguments.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2349
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2350
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2351
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2352 <h4 <%=heading_options%> ><a name="String.encode"><tt>String.encode (s)</tt></a></h4>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2353
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2354 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2355 Encodes argument <tt>s</tt> into a string that can be placed in quotes so as to return the original value of the string.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2356
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2357
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2358
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2359
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2360 <h4 <%=heading_options%> ><a name="String.find"><tt>String.find (s, pattern [, init [, plain]])</tt></a></h4>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2361
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2362 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2363 Looks for the first match of
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2364 <tt>pattern</tt> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) in the string <tt>s</tt>.
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2365 If it finds a match, then <tt>find</tt> returns the indices of&nbsp;<tt>s</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2366 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
2367 otherwise, it returns <b>nil</b>.
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2368 A third, optional numerical argument <tt>init</tt> specifies
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2369 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
2370 its default value is&nbsp;1 and can be negative.
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2371 A value of <b>true</b> as a fourth, optional argument <tt>plain</tt>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2372 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
2373 so the function does a plain "find substring" operation,
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2374 with no characters in <tt>pattern</tt> being considered magic.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2375 Note that if <tt>plain</tt> is given, then <tt>init</tt> 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
2376
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2377 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2378 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
2379 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
2380 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
2381 after the two indices.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2382
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2383
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2384
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2385
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2386 <h4 <%=heading_options%> ><a name="String.format"><tt>String.format (formatstring, &middot;&middot;&middot;)</tt></a></h4>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2387
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2388
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2389 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2390 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
2391 following the description given in its first argument (which must be a string).
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2392 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...)"><tt>String.format</tt></a> because Luan calls this internally.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2393
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2394 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2395 Note that Java's <tt>String.format</tt> is too stupid to convert between ints and floats, so you must provide the right kind of number.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2396
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2397
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2398
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2399 <h4 <%=heading_options%> ><a name="String.gmatch"><tt>String.gmatch (s, pattern)</tt></a></h4>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2400
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2401 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2402 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
2403 each time it is called,
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2404 returns the next captures from <tt>pattern</tt> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>)
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2405 over the string <tt>s</tt>.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2406 If <tt>pattern</tt> specifies no captures,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2407 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
2408
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2409
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2410 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2411 As an example, the following loop
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2412 will iterate over all the words from string <tt>s</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2413 printing one per line:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2414
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2415 <p><tt><pre>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2416 local s = "hello world from Lua"
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2417 for w in String.gmatch(s, [[\w+]]) do
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2418 print(w)
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2419 end
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2420 </pre></tt></p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2421
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2422 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2423 The next example collects all pairs <tt>key=value</tt> from the
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2424 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
2425
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2426 <p><tt><pre>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2427 local t = {}
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2428 local s = "from=world, to=Lua"
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2429 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
2430 t[k] = v
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2431 end
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2432 </pre></tt></p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2433
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2434 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2435 For this function, a caret '<tt>^</tt>' 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
2436 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
2437
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2438
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2439
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2440 <h4 <%=heading_options%> ><a name="String.gsub"><tt>String.gsub (s, pattern, repl [, n])</tt></a></h4>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2441
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2442 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2443 Returns a copy of <tt>s</tt>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2444 in which all (or the first <tt>n</tt>, if given)
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2445 occurrences of the <tt>pattern</tt> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) have been
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2446 replaced by a replacement string specified by <tt>repl</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2447 which can be a string, a table, or a function.
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2448 <tt>gsub</tt> 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
2449 the total number of matches that occurred.
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2450 The name <tt>gsub</tt> comes from <i>Global SUBstitution</i>.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2451
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2452
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2453 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2454 If <tt>repl</tt> is a string, then its value is used for replacement.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2455 The character&nbsp;<tt>\</tt> works as an escape character.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2456 Any sequence in <tt>repl</tt> of the form <tt>$<i>d</i></tt>,
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2457 with <i>d</i> between 1 and 9,
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2458 stands for the value of the <i>d</i>-th captured substring.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2459 The sequence <tt>$0</tt> stands for the whole match.
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2460
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2461
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2462 <p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2463 If <tt>repl</tt> 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
2464 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
2465
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2466
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2467 <p>
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2468 If <tt>repl</tt> 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
2469 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
2470 in order.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2471
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2472
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2473 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2474 In any case,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2475 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
2476 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
2477
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2478
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2479 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2480 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
2481 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
2482 then it is used as the replacement string;
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2483 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
2484 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
2485 (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
2486
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2487
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2488 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2489 Here are some examples:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2490
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2491 <p><tt><pre>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2492 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
2493 --&gt; 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
2494
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2495 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
2496 --&gt; x="hello hello 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 from Luan", [[(\w+)\s*(\w+)]], "$2 $1")
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2499 --&gt; x="world hello Luan from"
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2500
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2501 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
2502 return load(s)()
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2503 end)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2504 --&gt; x="4+5 = 9"
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2505
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2506 local t = {name="lua", version="5.3"}
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2507 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
2508 --&gt; x="lua-5.3.tar.gz"
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2509 </pre></tt></p>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2510
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2511
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2512
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2513 <h4 <%=heading_options%> ><a name="String.literal"><tt>String.literal (s)</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2514 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2515 Returns a string which matches the literal string <tt>s</tt> 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)"><tt>Pattern.quote</tt></a>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2516
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2517
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2518 <h4 <%=heading_options%> ><a name="String.lower"><tt>String.lower (s)</tt></a></h4>
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 553
diff changeset
2519 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2520 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
2521 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
2522 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
2523
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2524
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2525
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2526
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2527 <h4 <%=heading_options%> ><a name="String.match"><tt>String.match (s, pattern [, init])</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2528
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2529 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2530 Looks for the first <i>match</i> of
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2531 <tt>pattern</tt> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) in the string <tt>s</tt>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2532 If it finds one, then <tt>match</tt> returns
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2533 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
2534 otherwise it returns <b>nil</b>.
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2535 If <tt>pattern</tt> specifies no captures,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2536 then the whole match is returned.
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2537 A third, optional numerical argument <tt>init</tt> specifies
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2538 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
2539 its default value is&nbsp;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
2540
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2541
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2542 <h4 <%=heading_options%> ><a name="String.matches"><tt>String.matches (s, pattern)</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2543 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2544 Returns a boolean indicating whether the entire string <tt>s</tt> matches <tt>pattern</tt>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2545
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2546
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2547
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2548 <h4 <%=heading_options%> ><a name="String.rep"><tt>String.rep (s, n [, sep])</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2549 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2550 Returns a string that is the concatenation of <tt>n</tt> copies of
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2551 the string <tt>s</tt> separated by the string <tt>sep</tt>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2552 The default value for <tt>sep</tt> 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
2553 (that is, no separator).
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2554 Returns the empty string if <tt>n</tt> is not positive.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2555
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2557
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2558
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2559 <h4 <%=heading_options%> ><a name="String.reverse"><tt>String.reverse (s)</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2560 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2561 Returns a string that is the string <tt>s</tt> reversed.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2562
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2563
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2564
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2565
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2566 <h4 <%=heading_options%> ><a name="String.sub"><tt>String.sub (s, i [, j])</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2567
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2568 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2569 Returns the substring of <tt>s</tt> that
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2570 starts at <tt>i</tt> and continues until <tt>j</tt>;
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2571 <tt>i</tt> and <tt>j</tt> can be negative.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2572 If <tt>j</tt> 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
2573 (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
2574 In particular,
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2575 the call <tt>string.sub(s,1,j)</tt> returns a prefix of <tt>s</tt>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2576 with length <tt>j</tt>,
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2577 and <tt>string.sub(s, -i)</tt> returns a suffix of <tt>s</tt>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2578 with length <tt>i</tt>.
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2579
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2580
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2581 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2582 If, after the translation of negative indices,
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2583 <tt>i</tt> 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
2584 it is corrected to 1.
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2585 If <tt>j</tt> 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
2586 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
2587 If, after these corrections,
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2588 <tt>i</tt> is greater than <tt>j</tt>,
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2589 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
2590
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2591
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2592
556
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2593 <h4 <%=heading_options%> ><a name="String.to_binary"><tt>String.to_binary (s)</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2594
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2595 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2596 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()"><tt>String.getBytes</tt></a>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2597
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2598
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2599
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2600 <h4 <%=heading_options%> ><a name="String.to_number"><tt>String.to_number (s [, base])</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2601
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2602 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2603 When called with no <tt>base</tt>,
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2604 <tt>to_number</tt> tries to convert its argument to a number.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2605 If the argument is
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2606 a string convertible to a number,
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2607 then <tt>to_number</tt> returns this number;
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2608 otherwise, it returns <b>nil</b>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2609
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2610 The conversion of strings can result in integers or floats.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2611
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 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2614 When called with <tt>base</tt>,
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2615 then <tt>s</tt> must be a string to be interpreted as
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2616 an integer numeral in that base.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2617 In bases above&nbsp;10, the letter '<tt>A</tt>' (in either upper or lower case)
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2618 represents&nbsp;10, '<tt>B</tt>' represents&nbsp;11, and so forth,
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2619 with '<tt>Z</tt>' representing 35.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2620 If the string <tt>s</tt> is not a valid numeral in the given base,
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2621 the function returns <b>nil</b>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2622
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2623
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2624
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2625 <h4 <%=heading_options%> ><a name="String.trim"><tt>String.trim (s)</tt></a></h4>
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 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2628 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()"><tt>String.trim</tt></a>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2629
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2630
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2631
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2632
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2633 <h4 <%=heading_options%> ><a name="String.unicode"><tt>String.unicode (s [, i [, j]])</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2634
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2635 <p>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2636 Returns the internal numerical codes of the characters <tt>s[i]</tt>,
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2637 <tt>s[i+1]</tt>, ..., <tt>s[j]</tt>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2638 The default value for <tt>i</tt> is&nbsp;1;
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2639 the default value for <tt>j</tt> is&nbsp;<tt>i</tt>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2640 These indices are corrected
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2641 following the same rules of function <a href="#String.sub"><tt>String.sub</tt></a>.
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2642
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2643
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2644
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2645
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2646
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2647 <h4 <%=heading_options%> ><a name="String.upper"><tt>String.upper (s)</tt></a></h4>
d02f43598ba3 finish String documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
2648 <p>
371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2649 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
2650 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
2651 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
2652 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
2653
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2654
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2655
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2661 <h2>6.6 &ndash; <a name="6.6">Table Manipulation</a></h2>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2662
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2663 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2664 This library provides generic functions for table manipulation.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2665 It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2666
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2667
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2668 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2669 Remember that, whenever an operation needs the length of a table,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2670 the table must be a proper sequence
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2671 or have a <code>__len</code> metamethod (see <a href="#3.4.7">&sect;3.4.7</a>).
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2672 All functions ignore non-numeric keys
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2673 in the tables given as arguments.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2674
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2675
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2676 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2677 <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2678
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2679
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2680 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2681 Given a list where all elements are strings or numbers,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2682 returns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2683 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
2684 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
2685 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
2686 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
2687
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2688
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2689
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2690
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2691 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2692 <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2693
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2694
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2695 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2696 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
2697 shifting up the elements
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2698 <code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2699 The default value for <code>pos</code> is <code>#list+1</code>,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2700 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2701 of list <code>t</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2702
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2703
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2704
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2705
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2706 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2707 <hr><h3><a name="pdf-table.move"><code>table.move (a1, f, e, t [,a2])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2708
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2709
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2710 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2711 Moves elements from table <code>a1</code> to table <code>a2</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2712 This function performs the equivalent to the following
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2713 multiple assignment:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2714 <code>a2[t],&middot;&middot;&middot; = a1[f],&middot;&middot;&middot;,a1[e]</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2715 The default for <code>a2</code> is <code>a1</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2716 The destination range can overlap with the source range.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2717 Index <code>f</code> must be positive.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2718
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2719
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2720
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2721
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2722 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2723 <hr><h3><a name="pdf-table.pack"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2724
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2725
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2726 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2727 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
2728 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
2729 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
2730
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2731
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2732
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2733
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2734 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2735 <hr><h3><a name="pdf-table.remove"><code>table.remove (list [, pos])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2736
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2737
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2738 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2739 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
2740 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
2741 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
2742 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
2743 <code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2744 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
2745 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
2746 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
2747 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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2751 The default value for <code>pos</code> is <code>#list</code>,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2752 so that a call <code>table.remove(l)</code> removes the last element
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2753 of list <code>l</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2754
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2755
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2756
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2757
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2758 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2759 <hr><h3><a name="pdf-table.sort"><code>table.sort (list [, comp])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2760
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2761
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2762 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2763 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
2764 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
2765 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
2766 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
2767 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
2768 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
2769 (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
2770 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
2771 then the standard Lua operator <code>&lt;</code> is used instead.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2772
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2773
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2774 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2775 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
2776 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
2777 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
2778
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2779
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2780
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2781
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2782 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2783 <hr><h3><a name="pdf-table.unpack"><code>table.unpack (list [, i [, j]])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2784
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2785
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2786 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2787 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
2788 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
2789
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2790 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2791 return list[i], list[i+1], &middot;&middot;&middot;, list[j]
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2792 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2793 By default, <code>i</code> is&nbsp;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
2794
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2795
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2796
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2797
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2798
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2799
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2800
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2801 <h2>6.7 &ndash; <a name="6.7">Mathematical Functions</a></h2>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2802
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2803 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2804 This library provides basic mathematical functions.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2805 It provides all its functions and constants inside the table <a name="pdf-math"><code>math</code></a>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2806 Functions with the annotation "<code>integer/float</code>" give
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2807 integer results for integer arguments
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2808 and float results for float (or mixed) arguments.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2809 Rounding functions
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2810 (<a href="#pdf-math.ceil"><code>math.ceil</code></a>, <a href="#pdf-math.floor"><code>math.floor</code></a>, and <a href="#pdf-math.modf"><code>math.modf</code></a>)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2811 return an integer when the result fits in the range of an integer,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2812 or a float otherwise.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2813
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2814
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2815 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2816 <hr><h3><a name="pdf-math.abs"><code>math.abs (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2817
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2818
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2819 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2820 Returns the absolute value of <code>x</code>. (integer/float)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2821
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2822
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2823
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2824
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2825 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2826 <hr><h3><a name="pdf-math.acos"><code>math.acos (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2827
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2828
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2829 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2830 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
2831
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2832
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2833
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2834
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2835 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2836 <hr><h3><a name="pdf-math.asin"><code>math.asin (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2837
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2838
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2839 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2840 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
2841
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2842
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2843
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2844
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2845 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2846 <hr><h3><a name="pdf-math.atan"><code>math.atan (y [, x])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2847
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2848
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2849 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2850
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2851 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
2852 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
2853 quadrant of the result.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2854 (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
2855
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2856
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2857 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2858 The default value for <code>x</code> is 1,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2859 so that the call <code>math.atan(y)</code>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2860 returns the arc tangent of <code>y</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2861
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2862
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2863
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2864
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2865 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2866 <hr><h3><a name="pdf-math.ceil"><code>math.ceil (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2867
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 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
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2875 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2876 <hr><h3><a name="pdf-math.cos"><code>math.cos (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2877
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2878
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2879 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2880 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
2881
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2882
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2883
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2884
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2885 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2886 <hr><h3><a name="pdf-math.deg"><code>math.deg (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2887
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2888
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2889 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2890 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
2891
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2892
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2893
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2894
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2895 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2896 <hr><h3><a name="pdf-math.exp"><code>math.exp (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2897
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2900 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
2901 (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
2902
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2905
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2906 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2907 <hr><h3><a name="pdf-math.floor"><code>math.floor (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2908
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2909
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2910 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2911 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
2912
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2913
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2917 <hr><h3><a name="pdf-math.fmod"><code>math.fmod (x, y)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2918
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 remainder of the division of <code>x</code> by <code>y</code>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2922 that rounds the quotient towards zero. (integer/float)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2927 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2928 <hr><h3><a name="pdf-math.huge"><code>math.huge</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2929
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2930
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2931 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2932 The float value <code>HUGE_VAL</code>,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2933 a value larger than any other numerical value.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2934
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2935
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2938 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2939 <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2940
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2941
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2942 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2943 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
2944 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
2945 (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
2946
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2947
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2948
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2949
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2950 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2951 <hr><h3><a name="pdf-math.max"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2952
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 argument with the maximum value,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2956 according to the Lua operator <code>&lt;</code>. (integer/float)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2957
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2958
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2959
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2960
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2961 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2962 <hr><h3><a name="pdf-math.maxinteger"><code>math.maxinteger</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2963 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
2964
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2965
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2966
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2967
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2968 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2969 <hr><h3><a name="pdf-math.min"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2970
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2971
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2972 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2973 Returns the argument with the minimum value,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2974 according to the Lua operator <code>&lt;</code>. (integer/float)
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2978
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2979 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2980 <hr><h3><a name="pdf-math.mininteger"><code>math.mininteger</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2981 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
2982
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2983
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2984
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2985
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2986 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2987 <hr><h3><a name="pdf-math.modf"><code>math.modf (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2988
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2989
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2990 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2991 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2992 Its second result is always a float.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2993
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2994
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2995
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2996
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2997 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2998 <hr><h3><a name="pdf-math.pi"><code>math.pi</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2999
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3000
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3001 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3002 The value of <em>&pi;</em>.
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3005
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3006
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3007 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3008 <hr><h3><a name="pdf-math.rad"><code>math.rad (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3009
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3010
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3011 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3012 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
3013
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3018 <hr><h3><a name="pdf-math.random"><code>math.random ([m [, n]])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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>,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3026 <code>math.random</code> returns a pseudo-random integer
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3027 with uniform distribution in the range <em>[m, n]</em>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3028 (The value <em>m-n</em> cannot be negative and must fit in a Lua integer.)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3029 The call <code>math.random(n)</code> is equivalent to <code>math.random(1,n)</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3034 pseudo-random generator function provided by C.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3040 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3041 <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3042
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3043
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3044 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3045 Sets <code>x</code> as the "seed"
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3046 for the pseudo-random generator:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3047 equal seeds produce equal sequences of numbers.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3048
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3049
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3050
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3051
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3052 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3053 <hr><h3><a name="pdf-math.sin"><code>math.sin (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3057 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
3058
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3059
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3060
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3063 <hr><h3><a name="pdf-math.sqrt"><code>math.sqrt (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3064
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3065
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3066 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3067 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
3068 (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
3069
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3072
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3073 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3074 <hr><h3><a name="pdf-math.tan"><code>math.tan (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3075
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3076
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3077 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3078 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
3079
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3080
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3081
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3082
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3083 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3084 <hr><h3><a name="pdf-math.tointeger"><code>math.tointeger (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3085
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3086
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3087 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3088 If the value <code>x</code> is convertible to an integer,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3089 returns that integer.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3090 Otherwise, returns <b>nil</b>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3091
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3092
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 <hr><h3><a name="pdf-math.type"><code>math.type (x)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3097
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3098
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3099 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3100 Returns "<code>integer</code>" if <code>x</code> is an integer,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3101 "<code>float</code>" if it is a float,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3102 or <b>nil</b> if <code>x</code> is not a number.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3103
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3104
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3105
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3106
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3107 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3108 <hr><h3><a name="pdf-math.ult"><code>math.ult (m, n)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3109
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3112 Returns a boolean,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3113 true if integer <code>m</code> is below integer <code>n</code> when
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3114 they are compared as unsigned integers.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3120
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 <h2>6.8 &ndash; <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
3123
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3124 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3125 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
3126 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
3127 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
3128 default output file,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3129 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
3130 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
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 using implicit file handles,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3135 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
3136 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
3137 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
3138 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
3139
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3142 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
3143 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
3144 <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
3145 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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3149 Unless otherwise stated,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3150 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
3151 (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
3152 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
3153 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
3154 On non-POSIX systems,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3155 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
3156 in case of errors
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3157 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
3158 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
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 <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
3163
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3164
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3165 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3166 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
3167 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
3168
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3169
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3170
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3173 <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
3174
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3175
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3176 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3177 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
3178
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3179
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3180
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3181
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3182 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3183 <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
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 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
3188 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
3189 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
3190 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
3191 When called without parameters,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3192 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
3193
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3194
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3195 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3196 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
3197 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
3198
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3199
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3200
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3201
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3202 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3203 <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename &middot;&middot;&middot;])</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3204
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3205
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3206 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3207 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
3208 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
3209 works like <code>file:lines(&middot;&middot;&middot;)</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
3210 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
3211 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
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 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
3216 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
3217 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
3218 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
3219
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3220
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3221 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3222 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
3223 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
3224
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3225
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3226
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3227
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3228 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3229 <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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3233 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
3234 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
3235 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
3236 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
3237
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3238
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3239 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3240 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
3241
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3242 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3243 <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
3244 <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
3245 <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
3246 <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
3247 <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
3248 <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
3249 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
3250 </ul><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3251 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
3252 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
3253
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3254
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3255
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3256
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3257 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3258 <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
3259
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3260
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3261 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3262 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
3263
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3268 <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
3269
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3272 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
3273 on all platforms.
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3277 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
3278 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
3279 (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
3280 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
3281 (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
3282
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3283
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3284
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3285
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3286 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3287 <hr><h3><a name="pdf-io.read"><code>io.read (&middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3288
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3289
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3290 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3291 Equivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3292
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3297 <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
3298
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3301 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
3302 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
3303 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
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3308 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3309 <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
3310
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3311
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3312 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3313 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
3314 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
3315 <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
3316 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
3317
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3318
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3319
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3320
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3321 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3322 <hr><h3><a name="pdf-io.write"><code>io.write (&middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3323
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3324
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3325 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3326 Equivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3329
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3330
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3331 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3332 <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
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 Closes <code>file</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3337 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
3338 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
3339 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
3340
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3341
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3342 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3343 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
3344 <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
3345 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
3346
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3347
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3348
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3349
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3350 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3351 <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
3352
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3353
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3354 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3355 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
3356
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3357
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3358
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3359
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3360 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3361 <hr><h3><a name="pdf-file:lines"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3362
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3363
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3364 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3365 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
3366 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
3367 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
3368 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
3369 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
3370 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
3371
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3372 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3373 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
3374 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3375 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
3376 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
3377 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
3378 when the loop ends.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3379
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3380
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3381 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3382 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
3383 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
3384
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3385
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3386
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3389 <hr><h3><a name="pdf-file:read"><code>file:read (&middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3390
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3391
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3392 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3393 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
3394 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
3395 For each format,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3396 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
3397 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
3398 (In this latter case,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3399 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
3400 When called without formats,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3401 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
3402 (see below).
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3403
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3406 The available formats are
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3407
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3408 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3409
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3410 <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
3411 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
3412 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
3413 (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
3414 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
3415 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
3416 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
3417 (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
3418 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
3419 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3420
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3421 <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
3422 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
3423 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3424
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3425 <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
3426 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
3427 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
3428 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3429
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3430 <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
3431 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
3432 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
3433 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
3434 </li>
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 <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
3437 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
3438 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
3439 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3440
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3441 <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
3442 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
3443 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
3444 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
3445 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
3446 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
3447 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3448
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3449 </ul><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3450 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
3451
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3452
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3453
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3454
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3455 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3456 <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
3457
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3458
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3459 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3460 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
3461 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
3462 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
3463 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
3464
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3465 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3466 <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
3467 <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
3468 <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
3469 </ul><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3470 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
3471 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
3472 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
3473 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
3474
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3475
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3476 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3477 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
3478 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
3479 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
3480 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
3481 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
3482 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
3483 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
3484 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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3490 <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
3491
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3492
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3493 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3494 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
3495 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
3496
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3497 <ul>
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 <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
3500 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
3501 </li>
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 <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
3504 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
3505 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
3506 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
3507 </li>
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 <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
3510 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
3511 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
3512 (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
3513 </li>
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 </ul><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3516 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
3517 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
3518 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
3519
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3523 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3524 <hr><h3><a name="pdf-file:write"><code>file:write (&middot;&middot;&middot;)</code></a></h3>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3525
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3526
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3527 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3528 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
3529 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
3530
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3531
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3532 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3533 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
3534 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
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3538
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3539
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3540
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3541
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3542 <h2>6.9 &ndash; <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
3543
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3544 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3545 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
3546
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3547
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3548 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3549 <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
3550
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3551
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3552 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3553 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
3554 used by the program.
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3559 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3560 <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
3561
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3562
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3563 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3564 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
3565 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
3566
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3567
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3568 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3569 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
3570 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
3571 (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
3572 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
3573
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3576 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
3577 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
3578 After this optional character,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3579 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
3580 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
3581 <code>year</code> (four digits), <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3582 <code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59), <code>sec</code> (0&ndash;61),
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3583 <code>wday</code> (weekday, Sunday is&nbsp;1),
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3584 <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
3585 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
3586 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
3587 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
3588
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3589
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3590 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3591 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
3592 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
3593 formatted according to the same rules as the ISO&nbsp;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
3594
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3595
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3596 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3597 When called without arguments,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3598 <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
3599 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
3600 (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
3601
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3602
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3603 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3604 On non-POSIX systems,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3605 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
3606 because of its reliance on C&nbsp;function <code>gmtime</code> and C&nbsp;function <code>localtime</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3607
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3608
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 <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
3613
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3614
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3615 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3616 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
3617 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
3618 (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
3619 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
3620 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
3621
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3622
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3623
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3624
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3625 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3626 <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
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 This function is equivalent to the ISO&nbsp;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
3631 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
3632 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
3633 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
3634 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
3635 After this first result
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3636 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
3637 as follows:
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 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3640
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3641 <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
3642 the command terminated normally;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3643 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
3644 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3645
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3646 <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
3647 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
3648 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
3649 </li>
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 </ul>
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 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
3655 <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
3656
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3657
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3658
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3659
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3660 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3661 <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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3665 Calls the ISO&nbsp;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
3666 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
3667 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
3668 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
3669 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
3670 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
3671 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
3672 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
3673
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3674
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3675 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3676 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
3677 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
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3681
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3682 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3683 <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
3684
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3687 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
3688 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
3689
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3690
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 <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
3695
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3698 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
3699 with the given name.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3700 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
3701 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
3702
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3703
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3704
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3705
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3706 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3707 <hr><h3><a name="pdf-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
3708
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3709
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3710 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3711 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
3712 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
3713 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
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3717
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3718 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3719 <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
3720
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3721
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3722 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3723 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
3724 <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
3725 <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
3726 <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
3727 <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
3728 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
3729 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
3730 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
3731
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3732
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3733 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3734 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
3735 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
3736 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
3737 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
3738
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3739
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3740 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3741 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
3742 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
3743 for the given category.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3744
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3745
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3746 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3747 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
3748 because of its reliance on C&nbsp;function <code>setlocale</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3749
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3750
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3751
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3752
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3753 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3754 <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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3758 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
3759 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
3760 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
3761 and may have fields
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3762 <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
3763 <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
3764 <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
3765 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
3766 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
3767
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3768
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3769 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3770 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
3771 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
3772 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
3773 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
3774 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
3775 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
3776 <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
3777
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3778
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3779
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3780
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3781 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3782 <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
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 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
3787 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
3788 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
3789 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
3790
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3791
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3792 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3793 On POSIX systems,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3794 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
3795 to avoid security risks.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3796 (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
3797 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
3798 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
3799 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
3800
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3801
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3802 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3803 When possible,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3804 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
3805 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
3806
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3807
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3811
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3812
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3813 <h2>6.10 &ndash; <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
3814
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3815 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3816 This library provides
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3817 the functionality of the debug interface (<a href="#4.9">&sect;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
3818 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
3819 Several of its functions
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3820 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
3821 (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
3822 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
3823 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
3824 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
3825 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
3826 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
3827
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3828
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3829 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3830 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
3831 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
3832 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
3833 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
3834 thread to operate over.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3835 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
3836
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3837
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3838 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3839 <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
3840
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3841
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3842 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3843 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
3844 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
3845 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
3846 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
3847 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
3848 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
3849 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
3850
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3851
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3852 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3853 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
3854 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
3855
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3856
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3857
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3858
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3859 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3860 <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
3861
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3862
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3863 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3864 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
3865 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
3866 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
3867 (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
3868
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3869
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3870
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3873 <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
3874
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3875
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3876 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3877 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
3878 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
3879 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
3880 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
3881 of the given thread:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3882 level&nbsp;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
3883 level&nbsp;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
3884 (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
3885 and so on.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3886 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
3887 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
3888
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3889
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3890 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3891 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
3892 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
3893 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
3894 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
3895 If present,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3896 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
3897 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
3898 If present,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3899 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
3900 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
3901 valid lines.
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3904 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3905 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
3906 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
3907 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
3908 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
3909 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
3910 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
3911
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3915 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3916 <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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3920 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
3921 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
3922 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
3923 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
3924
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3925
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3926 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3927 The first parameter or local variable has index&nbsp;1, and so on,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3928 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
3929 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
3930 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
3931 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
3932 -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
3933 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
3934 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
3935 (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
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 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
3940 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
3941 (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
3942 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
3943
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3944
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3945 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3946 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
3947 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
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3951
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3952 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3953 <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
3954
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3955
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3956 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3957 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
3958 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
3959
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3962
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3963 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3964 <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
3965
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3966
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3967 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3968 Returns the registry table (see <a href="#4.5">&sect;4.5</a>).
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3972
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3973 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3974 <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
3975
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3976
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3977 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3978 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
3979 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
3980 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
3981
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3982
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3983 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3984 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
3985 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
3986 (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
3987
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3988
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3989
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3992 <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
3993
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3994
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3995 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3996 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
3997 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
3998 returns <b>nil</b>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3999
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4000
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4001
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4002
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4003 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4004 <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
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 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
4009 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
4010 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
4011 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
4012 with the given meaning:
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 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4015 <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
4016 <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
4017 <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
4018 </ul><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4019 Moreover,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4020 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
4021 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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4025 When called without arguments,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4026 <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
4027
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4030 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
4031 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
4032 <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
4033 <code>"return"</code>,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4034 <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
4035 For line events,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4036 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
4037 Inside a hook,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4038 you can call <code>getinfo</code> with level&nbsp;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
4039 the running function
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4040 (level&nbsp;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
4041 and level&nbsp;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
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4045
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4046 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4047 <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
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 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
4052 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
4053 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
4054 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
4055 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
4056 (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
4057 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
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 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
4062 variable indices and names.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4063
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4064
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4065
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4066
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4067 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4068 <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
4069
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4070
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4071 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4072 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
4073 (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
4074 Returns <code>value</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4075
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4076
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4079 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4080 <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
4081
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4084 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
4085 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
4086 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
4087 with the given index.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4088 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
4089
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4090
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4091
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4092
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4093 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4094 <hr><h3><a name="pdf-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
4095
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4096
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4097 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4098 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
4099 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
4100 <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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4104 Returns <code>udata</code>.
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4109 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4110 <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
4111
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4112
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4113 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4114 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
4115 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
4116 Otherwise,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4117 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
4118 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
4119 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
4120 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
4121 to start the traceback
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4122 (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
4123
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4124
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
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4127 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4128 <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
4129
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4130
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4131 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4132 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
4133 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
4134 from the given function.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4135
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4136
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4137 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4138 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
4139 closures share upvalues.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4140 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
4141 (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
4142 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
4143
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4144
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4145
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4146
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4147 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4148 <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
4149
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4152 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
4153 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
4154
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4155
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4156
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4157
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4158
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4159
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 <h1>7 &ndash; <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
4162
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4163 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4164 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
4165 to be embedded in a host C&nbsp;program,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4166 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
4167 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
4168 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
4169 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
4170 The standalone interpreter includes
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4171 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
4172 Its usage is:
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 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4175 lua [options] [script [args]]
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4176 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4177 The options are:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4178
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4179 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4180 <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
4181 <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
4182 <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
4183 <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
4184 <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
4185 <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
4186 <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
4187 </ul><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4188 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
4189 When called without arguments,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4190 <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
4191 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
4192 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
4193
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4194
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4195 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4196 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
4197 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
4198 (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
4199 before running any argument.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4200 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
4201 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
4202 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
4203
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4204
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4205 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4206 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
4207 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
4208 Lua also ignores
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4209 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
4210 setting the values of
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4211 <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
4212 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
4213
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4214
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4215 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4216 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
4217 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
4218
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4219 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4220 $ 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
4221 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4222 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
4223 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
4224 (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
4225
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4226
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4227 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4228 Before running any code,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4229 <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
4230 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
4231 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
4232 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
4233 and so on.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4234 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
4235 (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
4236 go to negative indices.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4237 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
4238
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4239 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4240 $ 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
4241 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4242 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
4243
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4244 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4245 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
4246 [0] = "b.lua",
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4247 [1] = "t1", [2] = "t2" }
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4248 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4249 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
4250 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
4251 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
4252 For instance, the call
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4253
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4254 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4255 $ 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
4256 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4257 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
4258 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
4259 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
4260 <code>arg[1]</code>, &middot;&middot;&middot;, <code>arg[#arg]</code>.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4261 (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
4262 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
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4266 In interactive mode,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4267 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
4268 After reading a line,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4269 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
4270 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
4271 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
4272 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
4273 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
4274 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
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 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
4279 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
4280 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
4281 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
4282 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
4283 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
4284 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
4285
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4286
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4287 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4288 When finishing normally,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4289 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
4290 (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
4291 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
4292 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
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 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
4297 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
4298 the standalone interpreter skips
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4299 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
4300 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
4301 by using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4302 as in
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 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4305 #!/usr/local/bin/lua
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4306 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4307 (Of course,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4308 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
4309 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
4310 then
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 <pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4313 #!/usr/bin/env lua
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4314 </pre><p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4315 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
4316
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4317
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4318
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4319 <h1>8 &ndash; <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
4320
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4321 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4322 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
4323 from Lua&nbsp;5.2 to Lua&nbsp;5.3.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4324 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
4325 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
4326 However,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4327 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
4328
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4329
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4330 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4331 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
4332 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
4333 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
4334 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
4335 Therefore,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4336 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
4337 different Lua versions.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4338 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
4339 using a new version.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4340
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4341
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4342 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4343 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
4344 of precompiled chunks;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4345 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
4346
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 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4349 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
4350 change between versions.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4351
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4352
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 <h2>8.1 &ndash; <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
4355 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4356
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4357 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4358 The main difference between Lua&nbsp;5.2 and Lua&nbsp;5.3 is the
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4359 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
4360 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
4361 some computations
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4362 (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
4363 can give different results.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4364
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4365
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4366 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4367 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
4368 (in Lua&nbsp;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
4369 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
4370 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
4371 (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
4372 for an occasional incompatibility;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4373 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
4374 For good programming,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4375 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
4376 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
4377 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4378
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4379 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4380 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
4381 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
4382 (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
4383 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
4384 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
4385 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
4386
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4387
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4388 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4389 (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
4390 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
4391 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
4392 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4393
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4394 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4395 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
4396 (It was an experimental feature in Lua&nbsp;5.2.)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4397 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4398
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4399 </ul>
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
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 <h2>8.2 &ndash; <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
4405 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4406
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4407 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4408 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
4409 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
4410 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
4411 (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
4412 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
4413 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4414
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4415 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4416 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
4417 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
4418 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4419
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4420 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4421 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
4422 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
4423 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4424
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4425 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4426 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
4427 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
4428 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4429
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4430 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4431 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
4432 <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
4433 <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
4434 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
4435 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
4436 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
4437 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
4438 For the other operations,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4439 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
4440 implement them in Lua.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4441 </li>
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 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4444 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
4445 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
4446 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
4447 (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
4448 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
4449 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
4450 (Lua&nbsp;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
4451 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
4452 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4453
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4454 </ul>
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 <h2>8.3 &ndash; <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
4460
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4461
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4462 <ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4463
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4464 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4465 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
4466 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
4467 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
4468 Adapt your code accordingly.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4469 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4470
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4471 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4472 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
4473 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
4474 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4475
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4476 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4477 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
4478 (<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
4479 <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
4480 were deprecated.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4481 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
4482 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4483
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4484 <li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4485 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
4486 (<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
4487 were deprecated.
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4488 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
4489 (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
4490 </li>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4491
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4492 </ul>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4493
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4494
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4495
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4496
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4497 <h1>9 &ndash; <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
4498
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4499 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4500 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
4501 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
4502 {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
4503 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
4504 (For operator precedences, see <a href="#3.4.8">&sect;3.4.8</a>;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4505 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
4506 Name, Numeral,
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4507 and LiteralString, see <a href="#3.1">&sect;3.1</a>.)
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4508
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4509
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4510
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4511
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4512 <pre>
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 chunk ::= block
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 block ::= {stat} [retstat]
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 stat ::= &lsquo;<b>;</b>&rsquo; |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4519 varlist &lsquo;<b>=</b>&rsquo; explist |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4520 functioncall |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4521 label |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4522 <b>break</b> |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4523 <b>goto</b> Name |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4524 <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
4525 <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
4526 <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
4527 <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
4528 <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; 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
4529 <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
4530 <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
4531 <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
4532 <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]
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 retstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]
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 label ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4537
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4538 funcname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4539
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4540 varlist ::= var {&lsquo;<b>,</b>&rsquo; var}
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 var ::= Name | prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; | prefixexp &lsquo;<b>.</b>&rsquo; Name
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 namelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4545
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4546 explist ::= exp {&lsquo;<b>,</b>&rsquo; exp}
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4547
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4548 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Numeral | LiteralString | &lsquo;<b>...</b>&rsquo; | functiondef |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4549 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
4550
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4551 prefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4552
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4553 functioncall ::= prefixexp args | prefixexp &lsquo;<b>:</b>&rsquo; Name args
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4554
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4555 args ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo; | tableconstructor | LiteralString
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4556
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4557 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
4558
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4559 funcbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4560
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4561 parlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4562
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4563 tableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4564
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4565 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
4566
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4567 field ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4568
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4569 fieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4570
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4571 binop ::= &lsquo;<b>+</b>&rsquo; | &lsquo;<b>-</b>&rsquo; | &lsquo;<b>*</b>&rsquo; | &lsquo;<b>/</b>&rsquo; | &lsquo;<b>//</b>&rsquo; | &lsquo;<b>^</b>&rsquo; | &lsquo;<b>%</b>&rsquo; |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4572 &lsquo;<b>&amp;</b>&rsquo; | &lsquo;<b>~</b>&rsquo; | &lsquo;<b>|</b>&rsquo; | &lsquo;<b>&gt;&gt;</b>&rsquo; | &lsquo;<b>&lt;&lt;</b>&rsquo; | &lsquo;<b>..</b>&rsquo; |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4573 &lsquo;<b>&lt;</b>&rsquo; | &lsquo;<b>&lt;=</b>&rsquo; | &lsquo;<b>&gt;</b>&rsquo; | &lsquo;<b>&gt;=</b>&rsquo; | &lsquo;<b>==</b>&rsquo; | &lsquo;<b>~=</b>&rsquo; |
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4574 <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
4575
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4576 unop ::= &lsquo;<b>-</b>&rsquo; | <b>not</b> | &lsquo;<b>#</b>&rsquo; | &lsquo;<b>~</b>&rsquo;
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4577
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4578 </pre>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4579
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4580 <p>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4581
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4582
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4583
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4584
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4585
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4586
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4587
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4588
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4589 <HR>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4590 <SMALL CLASS="footer">
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4591 Last update:
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4592 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
4593 </SMALL>
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4594 <!--
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4595 Last change: minor edit
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4596 -->
e01cddba3433 add manual.html as copy of Lua 5.3 Reference Manual
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4597
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 371
diff changeset
4598 </div>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 382
diff changeset
4599
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
4600 <% Html.simply_html_body_bottom() %>
2f5cc9c2cbf0 replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
4601 </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
4602 </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
4603 <%
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 382
diff changeset
4604 end