annotate website/src/manual.html.luan @ 1813:fa0e73119b7c

docs work
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 10 Jun 2024 23:19:40 -0600
parents f44dcb3fedf7
children e62c88b2883b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local head = Shared.head or error()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local docs_header = Shared.docs_header or error()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local show_toc = Shared.show_toc or error()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local show_content = Shared.show_content or error()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local content = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 intro = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 title = "Introduction"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 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.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 Luan is implemented in Java and is tightly coupled with Java. So it makes a great scripting language for Java programmers.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 Unlike Lua which is meant to be embedded, Luan is meant to be a full scripting language. This done not by adding features to Luan, but rather by providing a complete set of libraries.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 basic = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 title = "Basic Concepts"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 This section describes the basic concepts of the language.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 subs = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 types = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 title = "Values and Types"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 Luan is a <em>dynamically typed language</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 This means that
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 variables do not have types; only values do.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 There are no type definitions in the language.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 All values carry their own type.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 All values in Luan are <em>first-class values</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 This means that all values can be stored in variables,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 passed as arguments to other functions, and returned as results.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 There are eight basic types in Luan:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 <em>nil</em>, <em>boolean</em>, <em>number</em>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 <em>string</em>, <em>binary</em>, <em>function</em>, <em>java</em>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 and <em>table</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 <em>Nil</em> is the type of the value <b>nil</b>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 whose main property is to be different from any other value;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 it usually represents the absence of a useful value.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 <em>Nil</em> is implemented as the Java value <em>null</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 <em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 <em>Boolean</em> is implemented as the Java class <em>Boolean</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 <em>Number</em> represents both
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 integer numbers and real (floating-point) numbers.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 <em>Number</em> is implemented as the Java class <em>Number</em>. Any Java subclass of <em>Number</em> is allowed and this is invisible to the Luan user. Operations on numbers follow the same rules of
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 the underlying Java implementation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 <em>String</em> is implemented as the Java class <em>String</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 <em>Binary</em> is implemented as the Java type <em>byte[]</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79 Luan can call (and manipulate) functions written in Luan and
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80 functions written in Java (see <a href="#fn_calls">Function Calls</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 Both are represented by the type <em>function</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 The type <em>java</em> is provided to allow arbitrary Java objects to
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 be stored in Luan variables.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 A <em>java</em> value is a Java object that isn't one of the standard Luan types.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 Java values have no predefined operations in Luan,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 except assignment and identity test.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 Java values are useful when Java access is enabled in Luan.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 The type <em>table</em> implements associative arrays,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 that is, arrays that can be indexed not only with numbers,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 but with any Luan value except <b>nil</b>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 Tables can be <em>heterogeneous</em>;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 that is, they can contain values of all types (except <b>nil</b>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 Any key with value <b>nil</b> is not considered part of the table.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 Conversely, any key that is not part of a table has
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 an associated value <b>nil</b>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 Tables are the sole data-structuring mechanism in Luan;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106 they can be used to represent ordinary arrays, sequences,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 symbol tables, sets, records, graphs, trees, etc.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 To represent records, Luan uses the field name as an index.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 The language supports this representation by
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 providing <code>a.name</code> as syntactic sugar for <code>a["name"]</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111 There are several convenient ways to create tables in Luan
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112 (see <a href="#constructors">Table Constructors</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 We use the term <em>sequence</em> to denote a table where
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 the set of all positive numeric keys is equal to {1..<em>n</em>}
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 for some non-negative integer <em>n</em>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 which is called the length of the sequence (see <a href="#length">The Length Operator</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 Like indices,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 the values of table fields can be of any type.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 In particular,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 because functions are first-class values,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 table fields can contain functions.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 Thus tables can also carry <em>methods</em> (see <a href="#fn_def">Function Definitions</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 The indexing of tables follows
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 the definition of raw equality in the language.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 The expressions <code>a[i]</code> and <code>a[j]</code>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 denote the same table element
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 if and only if <code>i</code> and <code>j</code> are raw equal
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 (that is, equal without metamethods).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138 In particular, floats with integral values
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 are equal to their respective integers
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 (e.g., <code>1.0 == 1</code>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 Luan values are <em>objects</em>:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 variables do not actually <em>contain</em> values,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 only <em>references</em> to them.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 Assignment, parameter passing, and function returns
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 always manipulate references to values;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 these operations do not imply any kind of copy.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 The library function <a href="#Luan.type"><code>Luan.type</code></a> returns a string describing the type
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154 of a given value.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 env = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 title = "Environments"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164 The environment of a chunk starts with only one local variable: <code><a href="#require">require</a></code>. This function is 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>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 As will be discussed in <a href="#vars">Variables</a> and <a href=#assignment">Assignment</a>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 any reference to a free name
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 (that is, a name not bound to any declaration) <code>var</code>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171 can be syntactically translated to <code>_ENV.var</code> if <code>_ENV</code> is defined.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 error = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 title = "Error Handling"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181 Luan code can explicitly generate an error by calling the
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182 <a href="#Luan.error"><code>error</code></a> function.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183 If you need to catch errors in Luan,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 you can use the <a href="#try">Try Statement</code></a>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 Whenever there is an error,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189 an <em>error table</em>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190 is propagated with information about the error.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191 See <a href="#Luan.new_error"><code>Luan.new_error</code></a>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
192 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196 meta = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197 title = "Metatables and Metamethods"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
198 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
200 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
201 Every table in Luan can have a <em>metatable</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202 This <em>metatable</em> is an ordinary Luan table
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
203 that defines the behavior of the original value
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
204 under certain special operations.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205 You can change several aspects of the behavior
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
206 of operations over a value by setting specific fields in its metatable.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207 For instance, when a table is the operand of an addition,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208 Luan checks for a function in the field "<code>__add</code>" of the table's metatable.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
209 If it finds one,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
210 Luan calls this function to perform the addition.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
211 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
212
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
214 The keys in a metatable are derived from the <em>event</em> names;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
215 the corresponding values are called <ii>metamethods</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
216 In the previous example, the event is <code>"add"</code>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
217 and the metamethod is the function that performs the addition.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
218 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
219
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
220 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
221 You can query the metatable of any table
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
222 using the <a href="#Luan.get_metatable"><code>get_metatable</code></a> function.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
224
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
225 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
226 You can replace the metatable of tables
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
227 using the <a href="#Luan.set_metatable"><code>set_metatable</code></a> function.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
228 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
230 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
231 A metatable controls how a table behaves in
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232 arithmetic operations, bitwise operations,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
233 order comparisons, concatenation, length operation, calls, and indexing.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
234 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
235
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
236 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
237 A detailed list of events controlled by metatables is given next.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
238 Each operation is identified by its corresponding event name.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
239 The key for each event is a string with its name prefixed by
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
240 two underscores, '<code>__</code>';
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
241 for instance, the key for operation "add" is the
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
242 string "<code>__add</code>".
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
243 Note that queries for metamethods are always raw;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
244 the access to a metamethod does not invoke other metamethods.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
245 You can emulate how Luan queries a metamethod for an object <code>obj</code>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246 with the following code:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
247 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
248
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
249 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
250 raw_get(get_metatable(obj) or {}, "__" .. event_name)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
251 </code>
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
252
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
253 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
254 Here are the events:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
255 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
256
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
257 <ul>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
258
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
260 <b>"add": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
261 the <code>+</code> operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
262
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
263 If any operand for an addition is a table,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
264 Luan will try to call a metamethod.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
265 First, Luan will check the first operand (even if it is valid).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
266 If that operand does not define a metamethod for the "<code>__add</code>" event,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267 then Luan will check the second operand.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268 If Luan can find a metamethod,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
269 it calls the metamethod with the two operands as arguments,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
270 and the result of the call
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
271 (adjusted to one value)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
272 is the result of the operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
273 Otherwise,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
274 it raises an error.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
275 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
276
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
277 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
278 <b>"sub": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
279 the <code>-</code> operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
280 Behavior similar to the "add" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
281 </li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
283 <li><p><b>"mul": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
284 the <code>*</code> operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
285 Behavior similar to the "add" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
286 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
287
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
289 <b>"div": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
290 the <code>/</code> operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
291 Behavior similar to the "add" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
292 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
293
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
294 <li><p>
1680
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
295 <b>"idiv": </b>
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
296 the <code>//</code> operation.
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
297 Behavior similar to the "add" operation.
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
298 </p></li>
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
299
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
300 <li><p>
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
301 <b>"mod": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
302 the <code>%</code> operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
303 Behavior similar to the "add" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
304 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
305
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
306 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
307 <b>"pow": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
308 the <code>^</code> (exponentiation) operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
309 Behavior similar to the "add" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
310 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
311
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
312 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
313 <b>"unm": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
314 the <code>-</code> (unary minus) operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
315 Behavior similar to the "add" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
316 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
317
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
318 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
319 <b>"concat": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
320 the <code>..</code> (concatenation) operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
321 Behavior similar to the "add" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
322 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
323
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
324 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
325 <b>"len": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
326 the <code>#</code> (length) operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
327 If there is a metamethod,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
328 Luan calls it with the object as argument,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
329 and the result of the call
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
330 (always adjusted to one value)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
331 is the result of the operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
332 If there is no metamethod but the object is a table,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
333 then Luan uses the table length operation (see <a href="#length">The Length Operator</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
334 Otherwise, Luan raises an error.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
335 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
336
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
337 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
338 <b>"eq": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
339 the <code>==</code> (equal) operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
340 Behavior similar to the "add" operation,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
341 except that Luan will try a metamethod only when the values
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
342 being compared are both tables
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
343 and they are not primitively equal.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
344 The result of the call is always converted to a boolean.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
345 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
346
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
347 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
348 <b>"lt": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
349 the <code>&lt;</code> (less than) operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
350 Behavior similar to the "add" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
351 The result of the call is always converted to a boolean.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
352 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
353
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
354 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
355 <b>"le": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
356 the <code>&lt;=</code> (less equal) operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
357 Unlike other operations,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
358 The less-equal operation can use two different events.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
359 First, Luan looks for the "<code>__le</code>" metamethod in both operands,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
360 like in the "lt" operation.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
361 If it cannot find such a metamethod,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
362 then it will try the "<code>__lt</code>" event,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
363 assuming that <code>a &lt;= b</code> is equivalent to <code>not (b &lt; a)</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
364 As with the other comparison operators,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
365 the result is always a boolean.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
366 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
367
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
368 <li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
369 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
370 <b>"index": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
371 The indexing access <code>table[key]</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
372 This event happens
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
373 when <code>key</code> is not present in <code>table</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
374 The metamethod is looked up in <code>table</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
375 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
376
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
377 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
378 Despite the name,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
379 the metamethod for this event can be any type.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
380 If it is a function,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
381 it is called with <code>table</code> and <code>key</code> as arguments.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
382 Otherwise
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
383 the final result is the result of indexing this metamethod object with <code>key</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
384 (This indexing is regular, not raw,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
385 and therefore can trigger another metamethod if the metamethod object is a table.)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
386 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
387 </li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
388
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
389 <li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
390 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
391 <b>"new_index": </b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
392 The indexing assignment <code>table[key] = value</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
393 Like the index event,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
394 this event happens when
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
395 when <code>key</code> is not present in <code>table</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
396 The metamethod is looked up in <code>table</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
397 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
398
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
399 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
400 Like with indexing,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
401 the metamethod for this event can be either a function or a table.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
402 If it is a function,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
403 it is called with <code>table</code>, <code>key</code>, and <code>value</code> as arguments.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
404 If it is a table,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
405 Luan does an indexing assignment to this table with the same key and value.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
406 (This assignment is regular, not raw,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
407 and therefore can trigger another metamethod.)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
408 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
409
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
410 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
411 Whenever there is a "new_index" metamethod,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
412 Luan does not perform the primitive assignment.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
413 (If necessary,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
414 the metamethod itself can call <a href="#Luan.raw_set"><code>raw_set</code></a>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
415 to do the assignment.)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
416 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
417 </li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
418
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
419 <li><p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
420 <b>"gc":</b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
421 This is when a table is garbage collected. When the table's <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#finalize()">finalize</a> method is called by the Java garbage collector, if there is a "<code>__gc</code>" metamethod then it is called with the table as a parameter.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
422 </p></li>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
423
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
424 </ul>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
425 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
426 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
427 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
428 gc = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
429 title = "Garbage Collection"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
430 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
431 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
432 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
433 Luan uses Java's garbage collection.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
434 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
435 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
436 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
437 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
438 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
439 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
440 lang = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
441 title = "The Language"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
442 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
443 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
444 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
445 This section describes the lexis, the syntax, and the semantics of Luan.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
446 In other words,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
447 this section describes
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
448 which tokens are valid,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
449 how they can be combined,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
450 and what their combinations mean.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
451 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
452
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
453 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
454 Language constructs will be explained using the usual extended BNF notation,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
455 in which
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
456 {<em>a</em>}&nbsp;means&nbsp;0 or more <em>a</em>'s, and
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
457 [<em>a</em>]&nbsp;means an optional <em>a</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
458 Non-terminals are shown like non-terminal,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
459 keywords are shown like <b>kword</b>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
460 and other terminal symbols are shown like &lsquo;<b>=</b>&rsquo;.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
461 The complete syntax of Luan can be found in <a href="#9">&sect;9</a>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
462 at the end of this manual.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
463 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
464 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
465 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
466 subs = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
467 lex = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
468 title = "Lexical Conventions"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
469 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
470 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
471 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
472 Luan ignores spaces and comments
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
473 between lexical elements (tokens),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
474 except as delimiters between names and keywords.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
475 Luan considers the end of a line to be the end of a statement. This catches errors and encourages readability. If you want to continue a statement on another line, you can use a backslash followed by a newline which will be treated as white space.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
476 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
477
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
478 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
479 <em>Names</em>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
480 (also called <em>identifiers</em>)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
481 in Luan can be any string of letters,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
482 digits, and underscores,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
483 not beginning with a digit.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
484 Identifiers are used to name variables, table fields, and labels.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
485 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
486
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
487 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
488 The following <em>keywords</em> are reserved
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
489 and cannot be used as names:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
490 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
491
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
492 <p list=keywords>
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
493 <span>and</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
494 <span>break</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
495 <span>catch</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
496 <span>continue</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
497 <span>do</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
498 <span>else</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
499 <span>elseif</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
500 <span>end_do</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
501 <span>end_for</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
502 <span>end_function</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
503 <span>end_if</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
504 <span>end_try</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
505 <span>end_while</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
506 <span>false</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
507 <span>finally</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
508 <span>for</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
509 <span>function</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
510 <span>if</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
511 <span>in</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
512 <span>local</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
513 <span>nil</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
514 <span>not</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
515 <span>or</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
516 <span>repeat</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
517 <span>return</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
518 <span>then</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
519 <span>true</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
520 <span>try</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
521 <span>until</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
522 <span>while</span>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
523 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
524
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
525 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
526 Luan is a case-sensitive language:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
527 <code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
528 are two different, valid names.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
529 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
530
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
531 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
532 The following strings denote other tokens:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
533 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
534
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
535 <p list=tokens>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
536 <span>+</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
537 <span>-</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
538 <span>*</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
539 <span>/</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
540 <span>//</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
541 <span>%</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
542 <span>^</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
543 <span>#</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
544 <span>&amp;</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
545 <span>~</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
546 <span>|</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
547 <span>==</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
548 <span>~=</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
549 <span>&lt;=</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
550 <span>&gt;=</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
551 <span>&lt;</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
552 <span>&gt;</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
553 <span>=</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
554 <span>(</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
555 <span>)</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
556 <span>{</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
557 <span>}</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
558 <span>[</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
559 <span>]</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
560 <span>;</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
561 <span>,</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
562 <span>.</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
563 <span>..</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
564 <span>...</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
565 <span>%&gt;</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
566 <span>&lt;%</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
567 <span>&lt;%=</span>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
568 </p>
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
569
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
570 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
571 <em>Literal strings</em>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
572 can be delimited by matching single or double quotes,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
573 and can contain the following C-like escape sequences:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
574 '<code>\a</code>' (bell),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
575 '<code>\b</code>' (backspace),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
576 '<code>\f</code>' (form feed),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
577 '<code>\n</code>' (newline),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
578 '<code>\r</code>' (carriage return),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
579 '<code>\t</code>' (horizontal tab),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
580 '<code>\v</code>' (vertical tab),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
581 '<code>\\</code>' (backslash),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
582 '<code>\"</code>' (quotation mark [double quote]),
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
583 and '<code>\'</code>' (apostrophe [single quote]).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
584 A backslash followed by a real newline
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
585 results in a newline in the string.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
586 The escape sequence '<code>\z</code>' skips the following span
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
587 of white-space characters,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
588 including line breaks;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
589 it is particularly useful to break and indent a long literal string
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
590 into multiple lines without adding the newlines and spaces
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
591 into the string contents.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
592 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
593
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
594 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
595 Luan can specify any character in a literal string by its numerical value.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
596 This can be done
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
597 with the escape sequence <code>\x<em>XX</em></code>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
598 where <em>XX</em> is a sequence of exactly two hexadecimal digits,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
599 or with the escape sequence <code>\u<em>XXXX</em></code>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
600 where <em>XXXX</em> is a sequence of exactly four hexadecimal digits,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
601 or with the escape sequence <code>\<em>ddd</em></code>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
602 where <em>ddd</em> is a sequence of up to three decimal digits.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
603 (Note that if a decimal escape sequence is to be followed by a digit,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
604 it must be expressed using exactly three digits.)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
605 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
606
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
607 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
608 Literal strings can also be defined using a long format
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
609 enclosed by <em>long brackets</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
610 We define an <em>opening long bracket of level <em>n</em></em> as an opening
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
611 square bracket followed by <em>n</em> equal signs followed by another
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
612 opening square bracket.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
613 So, an opening long bracket of level 0 is written as <code>[[</code>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
614 an opening long bracket of level 1 is written as <code>[=[</code>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
615 and so on.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
616 A <em>closing long bracket</em> is defined similarly;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
617 for instance,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
618 a closing long bracket of level 4 is written as <code>]====]</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
619 A <em>long literal</em> starts with an opening long bracket of any level and
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
620 ends at the first closing long bracket of the same level.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
621 It can contain any text except a closing bracket of the same level.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
622 Literals in this bracketed form can run for several lines,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
623 do not interpret any escape sequences,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
624 and ignore long brackets of any other level.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
625 Any kind of end-of-line sequence
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
626 (carriage return, newline, carriage return followed by newline,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
627 or newline followed by carriage return)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
628 is converted to a simple newline.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
629 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
630
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
631 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
632 Any character in a literal string not
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
633 explicitly affected by the previous rules represents itself.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
634 However, Luan opens files for parsing in text mode,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
635 and the system file functions may have problems with
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
636 some control characters.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
637 So, it is safer to represent
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
638 non-text data as a quoted literal with
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
639 explicit escape sequences for non-text characters.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
640 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
641
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
642 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
643 For convenience,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
644 when the opening long bracket is immediately followed by a newline,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
645 the newline is not included in the string.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
646 As an example
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
647 the five literal strings below denote the same string:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
648 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
649
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
650 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
651 a = 'alo\n123"'
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
652 a = "alo\n123\""
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
653 a = '\97lo\10\04923"'
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
654 a = [[alo
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
655 123"]]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
656 a = [==[
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
657 alo
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
658 123"]==]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
659 </code>
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
660
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
661 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
662 A <em>numerical constant</em> (or <em>numeral</em>)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
663 can be written with an optional fractional part
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
664 and an optional decimal exponent,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
665 marked by a letter '<code>e</code>' or '<code>E</code>'.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
666 Luan also accepts hexadecimal constants,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
667 which start with <code>0x</code> or <code>0X</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
668 Hexadecimal constants also accept an optional fractional part
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
669 plus an optional binary exponent,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
670 marked by a letter '<code>p</code>' or '<code>P</code>'.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
671 A numeric constant with a fractional dot or an exponent
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
672 denotes a float;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
673 otherwise it denotes an integer.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
674 Examples of valid integer constants are
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
675 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
676
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
677 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
678 3 345 0xff 0xBEBADA
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
679 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
680
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
681 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
682 Examples of valid float constants are
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
683 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
684
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
685 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
686 3.0 3.1416 314.16e-2 0.31416E1 34e1
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
687 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
688 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
689
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
690 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
691 A <em>comment</em> starts with a double hyphen (<code>--</code>)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
692 anywhere outside a string.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
693 If the text immediately after <code>--</code> is not an opening long bracket,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
694 the comment is a <em>short comment</em>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
695 which runs until the end of the line.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
696 Otherwise, it is a <em>long comment</em>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
697 which runs until the corresponding closing long bracket.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
698 Long comments are frequently used to disable code temporarily.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
699 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
700 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
701 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
702 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
703 vars = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
704 title = "Variables"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
705 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
706 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
707 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
708 Variables are places that store values.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
709 There are three kinds of variables in Luan:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
710 global variables, local variables, and table fields.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
711 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
712
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
713 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
714 A single name can denote a global variable or a local variable
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
715 (or a function's formal parameter,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
716 which is a particular kind of local variable):
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
717 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
718
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
719 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
720 var ::= Name
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
721 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
722
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
723 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
724 Name denotes identifiers, as defined in <a href="#lex">Lexical Conventions</a>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
725 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
726
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
727 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
728 Local variables are <em>lexically scoped</em>:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
729 local variables can be freely accessed by functions
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
730 defined inside their scope (see <a href="#visibility">Visibility Rules</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
731 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
732
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
733 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
734 Before the first assignment to a variable, its value is <b>nil</b>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
735 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
736
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
737 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
738 Square brackets are used to index a table:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
739 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
740
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
741 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
742 var ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
743 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
744
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
745 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
746 The meaning of accesses to table fields can be changed via metatables.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
747 An access to an indexed variable <code>t[i]</code> is equivalent to
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
748 a call <code>gettable_event(t,i)</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
749 (See <a href="#meta">Metatables and Metamethods</a> for a complete description of the
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
750 <code>gettable_event</code> function.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
751 This function is not defined or callable in Luan.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
752 We use it here only for explanatory purposes.)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
753 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
754
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
755 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
756 The syntax <code>var.Name</code> is just syntactic sugar for
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
757 <code>var["Name"]</code>:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
758 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
759
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
760 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
761 var ::= prefixexp &lsquo;<b>.</b>&rsquo; Name
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
762 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
763
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
764 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
765 Global variables are not available by default. To enable global variable, you must define <code>_ENV</code> as a local variable whose value is a table. If <code>_ENV</code> is not defined, then an unrecognized variable name will produce a compile error. If <code>_ENV</code> is defined then an access to an unrecognized variable name will be consider a global variable. So then an acces to global variable <code>x</code>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
766 is equivalent to <code>_ENV.x</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
767 Due to the way that chunks are compiled,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
768 <code>_ENV</code> is never a global name (see <a href="#env">Environments</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
769 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
770 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
771 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
772 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
773 stmt = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
774 title = "Statements"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
775 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
776 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
777 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
778 Luan supports an almost conventional set of statements,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
779 similar to those in Pascal or C.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
780 This set includes
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
781 assignments, control structures, function calls,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
782 and variable declarations.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
783 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
784 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
785 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
786 subs = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
787 blocks = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
788 title = "Blocks"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
789 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
790 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
791 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
792 A block is a list of statements,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
793 which are executed sequentially:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
794 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
795
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
796 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
797 block ::= {stat}
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
798 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
799
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
800 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
801 Luan has <em>empty statements</em>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
802 that allow you to separate statements with semicolons,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
803 start a block with a semicolon
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
804 or write two semicolons in sequence:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
805 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
806
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
807 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
808 stat ::= &lsquo;<b>;</b>&rsquo;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
809 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
810
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
811 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
812 A block can be explicitly delimited to produce a single statement:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
813 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
814
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
815 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
816 stat ::= <b>do</b> block end_do
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
817 end_do ::= <b>end_do</b> | <b>end</b>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
818 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
819
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
820 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
821 Explicit blocks are useful
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
822 to control the scope of variable declarations.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
823 Explicit blocks are also sometimes used to
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
824 add a <b>return</b> statement in the middle
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
825 of another block (see <a href="#control">Control Structures</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
826 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
827 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
828 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
829 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
830 chunks = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
831 title = "Chunks"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
832 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
833 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
834 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
835 The unit of compilation of Luan is called a <em>chunk</em>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
836 Syntactically,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
837 a chunk is simply a block:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
838 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
839
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
840 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
841 chunk ::= block
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
842 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
843
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
844 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
845 Luan handles a chunk as the body of an anonymous function
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
846 with a variable number of arguments
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
847 (see <a href="#fn_def">Function Definitions</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
848 As such, chunks can define local variables,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
849 receive arguments, and return values.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
850 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
851
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
852 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
853 A chunk can be stored in a file or in a string inside the host program.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
854 To execute a chunk,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
855 Luan first <em>loads</em> it,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
856 compiling the chunk's code,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
857 and then Luan executes the compiled code.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
858 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
859 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
860 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
861 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
862 assignment = {
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
863 title = "Assignment"
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
864 content = function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
865 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
866 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
867 Luan allows multiple assignments.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
868 Therefore, the syntax for assignment
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
869 defines a list of variables on the left side
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
870 and a list of expressions on the right side.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
871 The elements in both lists are separated by commas:
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
872 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
873
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
874 <pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
875 stat ::= varlist &lsquo;<b>=</b>&rsquo; explist
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
876 varlist ::= var {&lsquo;<b>,</b>&rsquo; var}
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
877 explist ::= exp {&lsquo;<b>,</b>&rsquo; exp}
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
878 </pre>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
879
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
880 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
881 Expressions are discussed in <a href="#expressions">Expressions</a>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
882 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
883
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
884 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
885 Before the assignment,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
886 the list of values is <em>adjusted</em> to the length of
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
887 the list of variables.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
888 If there are more values than needed,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
889 the excess values are thrown away.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
890 If there are fewer values than needed,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
891 the list is extended with as many <b>nil</b>'s as needed.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
892 If the list of expressions ends with a function call,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
893 then all values returned by that call enter the list of values,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
894 before the adjustment
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
895 (except when the call is enclosed in parentheses; see <a href="#expressions">Expressions</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
896 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
897
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
898 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
899 The assignment statement first evaluates all its expressions
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
900 and only then the assignments are performed.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
901 Thus the code
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
902 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
903
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
904 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
905 i = 3
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
906 i, a[i] = i+1, 20
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
907 </code>
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
908
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
909 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
910 sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
911 because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
912 before it is assigned&nbsp;4.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
913 Similarly, the line
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
914 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
915
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
916 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
917 x, y = y, x
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
918 </code>
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
919
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
920 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
921 exchanges the values of <code>x</code> and <code>y</code>,
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
922 and
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
923 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
924
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
925 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
926 x, y, z = y, z, x
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
927 </code>
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
928
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
929 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
930 cyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
931 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
932
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
933 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
934 The meaning of assignments to global variables
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
935 and table fields can be changed via metatables.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
936 An assignment to an indexed variable <code>t[i] = val</code> is equivalent to
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
937 <code>settable_event(t,i,val)</code>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
938 (See <a href="#meta">Metatables and Metamethods</a> for a complete description of the
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
939 <code>settable_event</code> function.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
940 This function is not defined or callable in Luan.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
941 We use it here only for explanatory purposes.)
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
942 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
943
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
944 <p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
945 An assignment to a global name <code>x = val</code>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
946 is equivalent to the assignment
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
947 <code>_ENV.x = val</code> (see <a href="#env">Environments</a>).
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
948 Global names are only available when <code>_ENV</code> is defined.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
949 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
950 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
951 end
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
952 }
1660
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
953 control = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
954 title = "Control Structures"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
955 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
956 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
957 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
958 The control structures
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
959 <b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
960 familiar syntax:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
961 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
962
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
963 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
964 stat ::= <b>while</b> exp <b>do</b> block end_while
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
965 stat ::= <b>repeat</b> block <b>until</b> exp
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
966 stat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] end_if
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
967 end_while ::= <b>end_while</b> | <b>end</b>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
968 end_if ::= <b>end_if</b> | <b>end</b>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
969 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
970
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
971 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
972 Luan also has a <b>for</b> statement (see <a href="#for">For Statement</a>).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
973 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
974
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
975 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
976 The condition expression of a
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
977 control structure must be a boolean.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
978 Any other value type will produce an error.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
979 This helps catch errors and makes code more readable.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
980 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
981
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
982 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
983 In the <b>repeat</b>&ndash;<b>until</b> loop,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
984 the inner block does not end at the <b>until</b> keyword,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
985 but only after the condition.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
986 So, the condition can refer to local variables
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
987 declared inside the loop block.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
988 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
989
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
990 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
991 The <b>break</b> statement terminates the execution of a
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
992 <b>while</b>, <b>repeat</b>, or <b>for</b> loop,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
993 skipping to the next statement after the loop:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
994 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
995
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
996 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
997 stat ::= <b>break</b>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
998 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
999
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1000 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1001 A <b>break</b> ends the innermost enclosing loop.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1002 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1003
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1004 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1005 The <b>continue</b> statement jumps to the beginning of a
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1006 <b>while</b>, <b>repeat</b>, or <b>for</b> loop for next iteration,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1007 skipping the execution of statements inside the body of loop for the current iteration:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1008 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1009
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1010 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1011 stat ::= <b>continue</b>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1012 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1013
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1014 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1015 The <b>return</b> statement is used to return values
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1016 from a function or a chunk
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1017 (which is an anonymous function).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1018 Functions can return more than one value,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1019 so the syntax for the <b>return</b> statement is
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1020 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1021
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1022 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1023 stat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1024 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1025 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1026 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1027 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1028 ["for"] = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1029 title = "For Statement"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1030 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1031 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1032 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1033 The <b>for</b> statement works over functions,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1034 called <em>iterators</em>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1035 On each iteration, the iterator function is called to produce a new value,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1036 stopping when this new value is <b>nil</b>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1037 The <b>for</b> loop has the following syntax:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1038 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1039
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1040 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1041 stat ::= <b>for</b> namelist <b>in</b> exp <b>do</b> block end_for
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1042 namelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1043 end_for ::= <b>end_for</b> | <b>end</b>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1044 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1045
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1046 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1047 A <b>for</b> statement like
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1048 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1049
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1050 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1051 for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>exp</em> do <em>block</em> end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1052 </code>
1660
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1053
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1054 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1055 is equivalent to the code:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1056 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1057
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1058 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1059 do
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1060 local <em>f</em> = <em>exp</em>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1061 while true do
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1062 local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>()
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1063 if <em>var_1</em> == nil then break end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1064 <em>block</em>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1065 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1066 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1067 </code>
1660
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1068
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1069 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1070 Note the following:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1071 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1072
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1073 <ul>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1074 <li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1075 <code><em>exp</em></code> is evaluated only once.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1076 Its result is an <em>iterator</em> function.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1077 </li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1078 <li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1079 <code><em>f</em></code> is an invisible variable.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1080 The name is here for explanatory purposes only.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1081 </li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1082 <li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1083 You can use <b>break</b> to exit a <b>for</b> loop.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1084 </li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1085 <li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1086 The loop variables <code><em>var_i</em></code> are local to the loop;
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1087 you cannot use their values after the <b>for</b> ends.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1088 If you need these values,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1089 then assign them to other variables before breaking or exiting the loop.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1090 </li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1091 </ul>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1092 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1093 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1094 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1095 ["try"] = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1096 title = "Try Statement"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1097 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1098 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1099 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1100 The <b>try</b> statement has the same semantics as in Java.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1101 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1102
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1103 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1104 stat ::= <b>try</b> block [<b>catch</b> Name block] [<b>finally</b> block] end_try
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1105 end_try ::= <b>end_try</b> | <b>end</b>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1106 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1107 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1108 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1109 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1110 fn_stmt = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1111 title = "Function Calls as Statements"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1112 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1113 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1114 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1115 To allow possible side-effects,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1116 function calls can be executed as statements:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1117 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1118
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1119 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1120 stat ::= functioncall
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1121 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1122
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1123 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1124 In this case, all returned values are thrown away.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1125 Function calls are explained in <a href="#fn_calls">Function Calls</a>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1126 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1127 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1128 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1129 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1130 logical_stmt = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1131 title = "Logical Statement"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1132 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1133 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1134 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1135 <a href="#logical_ops">Logical expressions</a> can be statements.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1136 This is useful in cases like this:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1137 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1138
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1139 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1140 x==5 or error "x should be 5"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1141 </code>
1660
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1142 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1143 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1144 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1145 local_stmt = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1146 title = "Local Declarations"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1147 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1148 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1149 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1150 Local variables can be declared anywhere inside a block.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1151 The declaration can include an initial assignment:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1152 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1153
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1154 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1155 stat ::= <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1156 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1157
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1158 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1159 If present, an initial assignment has the same semantics
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1160 of a multiple assignment (see <a href="#assignment">Assignment</a>).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1161 Otherwise, all variables are initialized with <b>nil</b>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1162 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1163
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1164 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1165 A chunk is also a block (see <a href="#chunks">Chunks</a>),
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1166 and so local variables can be declared in a chunk outside any explicit block.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1167 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1168
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1169 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1170 The visibility rules for local variables are explained in <a href="#visibility">Visibility Rules</a>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1171 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1172 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1173 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1174 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1175 template_stmt = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1176 title = "Template Statements"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1177 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1178 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1179 <p>Template statements provide the full equivalent of <a href="http://en.wikipedia.org/wiki/JavaServer_Pages">JSP</a> but in a general way. Template statements write to standard output. For example:</p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1180 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1181
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1182 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1183 local name = "Bob"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1184 %&gt;
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1185 Hello &lt;%= name %&gt;!
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1186 Bye &lt;%= name %&gt;.
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1187 &lt;%
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1188 </code>
1660
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1189
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1190 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1191 is equivalent to the code:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1192 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1193
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1194 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1195 local name = "Bob"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1196 require("luan:Io.luan").stdout.write( "Hello ", name , "!\nBye ", name , ".\n" )
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1197 </code>
1660
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1198 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1199 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1200 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1201 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1202 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1203 expressions = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1204 title = "Expressions"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1205 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1206 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1207 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1208 The basic expressions in Luan are the following:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1209 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1210
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1211 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1212 exp ::= prefixexp
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1213 exp ::= <b>nil</b> | <b>false</b> | <b>true</b>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1214 exp ::= Numeral
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1215 exp ::= LiteralString
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1216 exp ::= functiondef
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1217 exp ::= tableconstructor
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1218 exp ::= &lsquo;<b>...</b>&rsquo;
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1219 exp ::= exp binop exp
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1220 exp ::= unop exp
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1221 prefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1222 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1223
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1224 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1225 Numerals and literal strings are explained in <a href="#lex">Lexical Conventions</a>;
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1226 variables are explained in <a href="#vars">Variables</a>;
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1227 function definitions are explained in <a href="#fn_def">Function Definitions</a>;
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1228 function calls are explained in <a href="#fn_calls">Function Calls</a>;
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1229 table constructors are explained in <a href="#constructors">Table Constructors</a>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1230 Vararg expressions,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1231 denoted by three dots ('<code>...</code>'), can only be used when
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1232 directly inside a vararg function;
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1233 they are explained in <a href="#fn_def">Function Definitions</a>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1234 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1235
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1236 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1237 Binary operators comprise arithmetic operators (see <a href="#arithmetic">Arithmetic Operators</a>),
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1238 relational operators (see <a href="#relational">Relational Operators</a>), logical operators (see <a href="#logical_ops">Logical Operators</a>),
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1239 and the concatenation operator (see <a href="#concatenation">Concatenation</a>).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1240 Unary operators comprise the unary minus (see <a href="#arithmetic">Arithmetic Operators</a>),
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1241 the unary logical <b>not</b> (see <a href="#logical_ops">Logical Operators</a>),
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1242 and the unary <em>length operator</em> (see <a href="#length">The Length Operator</a>).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1243 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1244
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1245 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1246 Both function calls and vararg expressions can result in multiple values.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1247 If a function call is used as a statement (see <a href="#fn_stmt">Function Calls as Statements</a>),
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1248 then its return list is adjusted to zero elements,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1249 thus discarding all returned values.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1250 If an expression is used as the last (or the only) element
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1251 of a list of expressions,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1252 then no adjustment is made
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1253 (unless the expression is enclosed in parentheses).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1254 In all other contexts,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1255 Luan adjusts the result list to one element,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1256 either discarding all values except the first one
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1257 or adding a single <b>nil</b> if there are no values.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1258 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1259
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1260 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1261 Here are some examples:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1262 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1263
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1264 <pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1265 f() -- adjusted to 0 results
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1266 g(f(), x) -- f() is adjusted to 1 result
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1267 g(x, f()) -- g gets x plus all results from f()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1268 a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil)
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1269 a,b = ... -- a gets the first vararg parameter, b gets
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1270 -- the second (both a and b can get nil if there
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1271 -- is no corresponding vararg parameter)
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1272
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1273 a,b,c = x, f() -- f() is adjusted to 2 results
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1274 a,b,c = f() -- f() is adjusted to 3 results
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1275 return f() -- returns all results from f()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1276 return ... -- returns all received vararg parameters
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1277 return x,y,f() -- returns x, y, and all results from f()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1278 {f()} -- creates a list with all results from f()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1279 {...} -- creates a list with all vararg parameters
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1280 {f(), nil} -- f() is adjusted to 1 result
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1281 </pre>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1282
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1283 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1284 Any expression enclosed in parentheses always results in only one value.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1285 Thus,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1286 <code>(f(x,y,z))</code> is always a single value,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1287 even if <code>f</code> returns several values.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1288 (The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1289 or <b>nil</b> if <code>f</code> does not return any values.)
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1290 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1291 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1292 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1293 subs = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1294 arithmetic = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1295 title = "Arithmetic Operators"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1296 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1297 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1298 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1299 Luan supports the following arithmetic operators:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1300 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1301
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1302 <ul>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1303 <li><b><code>+</code>: </b>addition</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1304 <li><b><code>-</code>: </b>subtraction</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1305 <li><b><code>*</code>: </b>multiplication</li>
1680
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
1306 <li><b><code>/</code>: </b>float division</li>
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
1307 <li><b><code>//</code>: </b>floor division</li>
1660
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1308 <li><b><code>%</code>: </b>modulo</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1309 <li><b><code>^</code>: </b>exponentiation</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1310 <li><b><code>-</code>: </b>unary minus</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1311 </ul>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1312
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1313 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1314 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.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1315 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1316
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1317 <p>
1680
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
1318 Floor division (//) is a division that rounds the quotient towards minus infinity, that is, the floor of the division of its operands.
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
1319 </p>
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
1320
9ef19f5ea973 add // operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1670
diff changeset
1321 <p>
1660
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1322 Modulo is defined as the remainder of a division
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1323 that rounds the quotient towards minus infinite (floor division).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1324 (The Java modulo operator is not used.)
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1325 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1326 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1327 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1328 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1329 conversions = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1330 title = "Coercions and Conversions"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1331 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1332 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1333 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1334 Luan generally avoids automatic conversions.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1335 String concatenation automatically converts all of its arguments to strings.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1336 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1337
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1338 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1339 Luan provides library functions for explicit type conversions.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1340 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1341 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1342 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1343 }
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1344 relational = {
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1345 title = "Relational Operators"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1346 content = function()
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1347 %>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1348 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1349 Luan supports the following relational operators:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1350 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1351
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1352 <ul>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1353 <li><b><code>==</code>: </b>equality</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1354 <li><b><code>~=</code>: </b>inequality</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1355 <li><b><code>&lt;</code>: </b>less than</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1356 <li><b><code>&gt;</code>: </b>greater than</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1357 <li><b><code>&lt;=</code>: </b>less or equal</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1358 <li><b><code>&gt;=</code>: </b>greater or equal</li>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1359 </ul>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1360
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1361 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1362 These operators always result in <b>false</b> or <b>true</b>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1363 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1364
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1365 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1366 Equality (<code>==</code>) first compares the type of its operands.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1367 If the types are different, then the result is <b>false</b>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1368 Otherwise, the values of the operands are compared.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1369 Strings, numbers, and binary values are compared in the obvious way (by value).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1370 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1371
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1372 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1373 Tables
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1374 are compared by reference:
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1375 two objects are considered equal only if they are the same object.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1376 Every time you create a new table,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1377 it is different from any previously existing table.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1378 Closures are also compared by reference.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1379 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1380
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1381 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1382 You can change the way that Luan compares tables
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1383 by using the "eq" metamethod (see <a href="#meta">Metatables and Metamethods</a>).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1384 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1385
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1386 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1387 Java values are compared for equality with the Java <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)"><code>equals</code></a> method.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1388 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1389
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1390 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1391 Equality comparisons do not convert strings to numbers
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1392 or vice versa.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1393 Thus, <code>"0"==0</code> evaluates to <b>false</b>,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1394 and <code>t[0]</code> and <code>t["0"]</code> denote different
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1395 entries in a table.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1396 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1397
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1398 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1399 The operator <code>~=</code> is exactly the negation of equality (<code>==</code>).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1400 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1401
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1402 <p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1403 The order operators work as follows.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1404 If both arguments are numbers,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1405 then they are compared following
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1406 the usual rule for binary operations.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1407 Otherwise, if both arguments are strings,
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1408 then their values are compared according to the current locale.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1409 Otherwise, Luan tries to call the "lt" or the "le"
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1410 metamethod (see <a href="#meta">Metatables and Metamethods</a>).
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1411 A comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1412 and <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1413 </p>
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1414 <%
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1415 end
2968e43cdd44 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1656
diff changeset
1416 }
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1417 logical_ops = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1418 title = "Logical Operators"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1419 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1420 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1421 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1422 The logical operators in Luan are
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1423 <b>and</b>, <b>or</b>, and <b>not</b>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1424 The <b>and</b> and <b>or</b> operators consider both <b>false</b> and <b>nil</b> as false
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1425 and anything else as true.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1426 Like the control structures (see <a href="#control">Control Structures</a>),
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1427 the <b>not</b> operator requires a boolean value.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1428 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1429
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1430 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1431 The negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1432 The conjunction operator <b>and</b> returns its first argument
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1433 if this value is <b>false</b> or <b>nil</b>;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1434 otherwise, <b>and</b> returns its second argument.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1435 The disjunction operator <b>or</b> returns its first argument
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1436 if this value is different from <b>nil</b> and <b>false</b>;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1437 otherwise, <b>or</b> returns its second argument.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1438 Both <b>and</b> and <b>or</b> use short-circuit evaluation;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1439 that is,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1440 the second operand is evaluated only if necessary.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1441 Here are some examples:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1442 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1443
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1444 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1445 10 or 20 --&gt; 10
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1446 10 or error() --&gt; 10
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1447 nil or "a" --&gt; "a"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1448 nil and 10 --&gt; nil
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1449 false and error() --&gt; false
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1450 false and nil --&gt; false
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1451 false or nil --&gt; nil
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1452 10 and 20 --&gt; 20
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1453 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1454
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1455 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1456 (In this manual,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1457 <code>--&gt;</code> indicates the result of the preceding expression.)
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1458 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1459 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1460 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1461 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1462 concatenation = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1463 title = "Concatenation"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1464 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1465 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1466 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1467 The string concatenation operator in Luan is
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1468 denoted by two dots ('<code>..</code>').
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1469 All operands are converted to strings.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1470 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1471 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1472 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1473 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1474 length = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1475 title = "The Length Operator"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1476 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1477 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1478 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1479 The length operator is denoted by the unary prefix operator <code>#</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1480 The length of a string is its number of characters.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1481 The length of a binary is its number of bytes.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1482 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1483
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1484 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1485 A program can modify the behavior of the length operator for
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1486 any table through the <code>__len</code> metamethod (see <a href="#meta">Metatables and Metamethods</a>).
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1487 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1488
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1489 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1490 Unless a <code>__len</code> metamethod is given,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1491 the length of a table <code>t</code> is defined
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1492 as the number of elements in <em>sequence</em>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1493 that is,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1494 the size of the set of its positive numeric keys is equal to <em>{1..n}</em>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1495 for some non-negative integer <em>n</em>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1496 In that case, <em>n</em> is its length.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1497 Note that a table like
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1498 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1499
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1500 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1501 {10, 20, nil, 40}
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1502 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1503
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1504 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1505 has a length of <code>2</code>, because that is the last key in sequence.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1506 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1507 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1508 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1509 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1510 precedence = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1511 title = "Precedence"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1512 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1513 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1514 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1515 Operator precedence in Luan follows the table below,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1516 from lower to higher priority:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1517 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1518
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1519 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1520 or
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1521 and
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1522 &lt; &gt; &lt;= &gt;= ~= ==
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1523 ..
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1524 + -
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1525 * / %
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1526 unary operators (not # -)
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1527 ^
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1528 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1529
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1530 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1531 As usual,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1532 you can use parentheses to change the precedences of an expression.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1533 The concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1534 operators are right associative.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1535 All other binary operators are left associative.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1536 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1537 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1538 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1539 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1540 constructors = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1541 title = "Table Constructors"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1542 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1543 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1544 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1545 Table constructors are expressions that create tables.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1546 Every time a constructor is evaluated, a new table is created.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1547 A constructor can be used to create an empty table
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1548 or to create a table and initialize some of its fields.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1549 The general syntax for constructors is
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1550 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1551
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1552 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1553 tableconstructor ::= &lsquo;<b>{</b>&rsquo; fieldlist &lsquo;<b>}</b>&rsquo;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1554 fieldlist ::= [field] {fieldsep [field]}
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1555 field ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1556 fieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo; | <b>end_of_line</b>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1557 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1558
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1559 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1560 Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1561 with key <code>exp1</code> and value <code>exp2</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1562 A field of the form <code>name = exp</code> is equivalent to
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1563 <code>["name"] = exp</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1564 Finally, fields of the form <code>exp</code> are equivalent to
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1565 <code>[i] = exp</code>, where <code>i</code> are consecutive integers
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1566 starting with 1.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1567 Fields in the other formats do not affect this counting.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1568 For example,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1569 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1570
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1571 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1572 a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1573 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1574
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1575 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1576 is equivalent to
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1577 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1578
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1579 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1580 do
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1581 local t = {}
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1582 t[f(1)] = g
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1583 t[1] = "x" -- 1st exp
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1584 t[2] = "y" -- 2nd exp
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1585 t.x = 1 -- t["x"] = 1
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1586 t[3] = f(x) -- 3rd exp
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1587 t[30] = 23
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1588 t[4] = 45 -- 4th exp
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1589 a = t
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1590 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1591 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1592
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1593 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1594 The order of the assignments in a constructor is undefined.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1595 (This order would be relevant only when there are repeated keys.)
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1596 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1597
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1598 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1599 If the last field in the list has the form <code>exp</code>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1600 and the expression is a function call or a vararg expression,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1601 then all values returned by this expression enter the list consecutively
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1602 (see <a href="#fn_calls">Function Calls</a>).
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1603 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1604
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1605 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1606 The field list can have an optional trailing separator,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1607 as a convenience for machine-generated code.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1608 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1609 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1610 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1611 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1612 fn_calls = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1613 title = "Function Calls"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1614 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1615 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1616 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1617 A function call in Luan has the following syntax:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1618 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1619
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1620 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1621 functioncall ::= prefixexp args
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1622 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1623
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1624 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1625 In a function call,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1626 first prefixexp and args are evaluated.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1627 The value of prefixexp must have type <em>function</em>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1628 This function is called
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1629 with the given arguments.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1630 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1631
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1632 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1633 Arguments have the following syntax:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1634 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1635
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1636 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1637 args ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1638 args ::= tableconstructor
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1639 args ::= LiteralString
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1640 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1641
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1642 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1643 All argument expressions are evaluated before the call.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1644 A call of the form <code>f{<em>fields</em>}</code> is
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1645 syntactic sugar for <code>f({<em>fields</em>})</code>;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1646 that is, the argument list is a single new table.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1647 A call of the form <code>f'<em>string</em>'</code>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1648 (or <code>f"<em>string</em>"</code> or <code>f[[<em>string</em>]]</code>)
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1649 is syntactic sugar for <code>f('<em>string</em>')</code>;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1650 that is, the argument list is a single literal string.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1651 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1652 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1653 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1654 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1655 fn_def = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1656 title = "Function Definitions"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1657 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1658 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1659 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1660 The syntax for function definition is
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1661 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1662
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1663 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1664 functiondef ::= <b>function</b> funcbody
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1665 funcbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block end_function
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1666 end_function ::= <b>end_function</b> | <b>end</b>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1667 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1668
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1669 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1670 The following syntactic sugar simplifies function definitions:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1671 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1672
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1673 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1674 stat ::= <b>function</b> funcname funcbody
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1675 stat ::= <b>local</b> <b>function</b> Name funcbody
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1676 funcname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1677 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1678
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1679 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1680 The statement
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1681 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1682
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1683 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1684 function f () <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1685 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1686
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1687 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1688 translates to
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1689 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1690
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1691 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1692 f = function () <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1693 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1694
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1695 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1696 The statement
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1697 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1698
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1699 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1700 function t.a.b.c.f () <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1701 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1702
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1703 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1704 translates to
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1705 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1706
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1707 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1708 t.a.b.c.f = function () <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1709 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1710
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1711 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1712 The statement
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1713 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1714
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1715 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1716 local function f () <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1717 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1718
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1719 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1720 translates to
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1721 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1722
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1723 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1724 local f; f = function () <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1725 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1726
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1727 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1728 not to
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1729 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1730
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1731 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1732 local f = function () <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1733 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1734
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1735 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1736 (This only makes a difference when the body of the function
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1737 contains references to <code>f</code>.)
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1738 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1739
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1740 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1741 A function definition is an executable expression,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1742 whose value has type <em>function</em>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1743 When Luan precompiles a chunk,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1744 all its function bodies are precompiled too.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1745 Then, whenever Luan executes the function definition,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1746 the function is <em>instantiated</em> (or <em>closed</em>).
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1747 This function instance (or <em>closure</em>)
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1748 is the final value of the expression.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1749 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1750
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1751 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1752 Parameters act as local variables that are
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1753 initialized with the argument values:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1754 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1755
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1756 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1757 parlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1758 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1759
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1760 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1761 When a function is called,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1762 the list of arguments is adjusted to
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1763 the length of the list of parameters if the list is too short,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1764 unless the function is a <em>vararg function</em>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1765 which is indicated by three dots ('<code>...</code>')
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1766 at the end of its parameter list.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1767 A vararg function does not adjust its argument list;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1768 instead, it collects all extra arguments and supplies them
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1769 to the function through a <em>vararg expression</em>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1770 which is also written as three dots.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1771 The value of this expression is a list of all actual extra arguments,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1772 similar to a function with multiple results.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1773 If a vararg expression is used inside another expression
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1774 or in the middle of a list of expressions,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1775 then its return list is adjusted to one element.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1776 If the expression is used as the last element of a list of expressions,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1777 then no adjustment is made
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1778 (unless that last expression is enclosed in parentheses).
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1779 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1780
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1781 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1782 As an example, consider the following definitions:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1783 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1784 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1785 function f(a, b) end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1786 function g(a, b, ...) end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1787 function r() return 1,2,3 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1788 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1789
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1790 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1791 Then, we have the following mapping from arguments to parameters and
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1792 to the vararg expression:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1793 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1794 <pre>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1795 CALL PARAMETERS
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1796
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1797 f(3) a=3, b=nil
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1798 f(3, 4) a=3, b=4
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1799 f(3, 4, 5) runtime error
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1800 f(r(), 10) runtime error
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1801 f(r()) runtime error
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1802
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1803 g(3) a=3, b=nil, ... --&gt; (nothing)
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1804 g(3, 4) a=3, b=4, ... --&gt; (nothing)
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1805 g(3, 4, 5, 8) a=3, b=4, ... --&gt; 5 8
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1806 g(5, r()) a=5, b=1, ... --&gt; 2 3
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1807 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1808
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1809 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1810 Results are returned using the <b>return</b> statement (see <a href="#control">Control Structures</a>).
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1811 If control reaches the end of a function
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1812 without encountering a <b>return</b> statement,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1813 then the function returns with no results.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1814 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1815 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1816 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1817 }
1797
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1818 backticks = {
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1819 title = "Backticks"
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1820 content = function()
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1821 %>
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1822 <p>
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1823 A block between backticks is run and then whatever was sent to standard output is returned as a string. Examples:
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1824 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1825 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1826 local s = `%&gt;1 + 1 = &lt;%=1+1%&gt;&lt;%`
1797
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1827
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1828 local s = ` fn(whatever) `
1797
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1829
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1830 local s = `%&gt;
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1831 ...
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1832 &lt;%`
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1833 </code>
1797
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1834 <p>
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1835 Backticks complement <a href="#template_stmt">template statements</a>.
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1836 </p>
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1837 <%
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1838 end
ba43135bb98d backticks docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1722
diff changeset
1839 }
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1840 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1841 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1842 visibility = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1843 title = "Visibility Rules"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1844 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1845 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1846 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1847 Luan is a lexically scoped language.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1848 The scope of a local variable begins at the first statement after
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1849 its declaration and lasts until the last non-void statement
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1850 of the innermost block that includes the declaration.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1851 Consider the following example:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1852 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1853 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1854 local x = 10 -- global to module
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1855 do -- new block
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1856 local x = x -- new 'x', with value 10
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1857 print(x) --&gt; 10
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1858 x = x+1
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1859 do -- another block
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1860 local x = x+1 -- another 'x'
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1861 print(x) --&gt; 12
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1862 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1863 print(x) --&gt; 11
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1864 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1865 print(x) --&gt; 10 (the global one)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1866 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1867
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1868 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1869 Notice that, in a declaration like <code>local x = x</code>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1870 the new <code>x</code> being declared is not in scope yet,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1871 and so the second <code>x</code> refers to the outside variable.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1872 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1873
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1874 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1875 Because of the lexical scoping rules,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1876 local variables can be freely accessed by functions
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1877 defined inside their scope.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1878 A local variable used by an inner function is called
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1879 an <em>upvalue</em>, or <em>external local variable</em>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1880 inside the inner function.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1881 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1882
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1883 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1884 Notice that each execution of a <b>local</b> statement
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1885 defines new local variables.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1886 Consider the following example:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1887 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1888
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1889 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1890 local a = {}
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1891 local x = 20
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1892 for i=1,10 do
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1893 local y = 0
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1894 a[i] = function () y=y+1; return x+y end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1895 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1896 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1897
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1898 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1899 The loop creates ten closures
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1900 (that is, ten instances of the anonymous function).
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1901 Each of these closures uses a different <code>y</code> variable,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1902 while all of them share the same <code>x</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1903 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1904 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1905 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1906 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1907 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1908 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1909 libs = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1910 title = "Standard Libraries"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1911 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1912 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1913 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1914 The standard Luan libraries provide useful functions
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1915 that are implemented both in Java and in Luan itself.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1916 How each function is implemented shouldn't matter to the user.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1917 Some of these functions provide essential services to the language
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1918 (e.g., <a href="#Luan.type"><code>type</code></a> and <a href="#Luan.get_metatable"><code>get_metatable</code></a>);
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1919 others provide access to "outside" services (e.g., I/O).
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1920 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1921 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1922 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1923 subs = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1924 default_lib = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1925 title = "Default Environment"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1926 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1927 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1928 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1929 This is provided by default as a local variable for any Luan code as described in <a href="#env">Environments</a>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1930 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1931 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1932 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1933 subs = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1934 require = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1935 title = "require (mod_uri)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1936 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1937 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1938 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1939 Example use:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1940 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1941 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1942 local Table = require "luan:Table.luan"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1943 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1944
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1945 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1946 Could be defined as:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1947 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1948 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1949 local function require(mod_name)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1950 return <a href="#Package.load">Package.load</a>(mod_name) or <a href="#Luan.error">Luan.error</a>("module '"..mod_name.."' not found")
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1951 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1952 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1953
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1954 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1955 A special case is:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1956 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1957 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1958 require "java"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1959 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1960
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1961 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1962 This 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.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1963 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1964 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1965 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1966 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1967 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1968 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1969 luan_lib = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1970 title = "Basic Functions"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1971 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1972 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1973 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1974 Include this library by:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1975 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1976
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1977 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1978 local Luan = require "luan:Luan.luan"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
1979 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1980
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1981 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1982 The basic library provides basic functions to Luan that don't depend on other libaries.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1983 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1984 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1985 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
1986 subs = {
1813
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1987 ["Luan.arg"] = {
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1988 title = "Luan.arg"
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1989 content = function()
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1990 %>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1991 <p>If Luan was run from the command line then this is a list of the command line arguments. For example if one runs Luan like this:</p>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1992
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1993 <code block>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1994 luan t.luan a b c
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1995 </code>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1996
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1997 <p>Then Luan.arg will contain:</p>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1998
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
1999 <code block>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2000 {
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2001 [0] = "t.luan"
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2002 [1] = "a"
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2003 [2] = "b"
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2004 [3] = "c"
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2005 }
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2006 </code>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2007
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2008 <p>And of course <code>#Luan.arg</code> will be <code>3</code>.</p>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2009 <%
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2010 end
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2011 }
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2012 ["Luan.do_file"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2013 title = "Luan.do_file ([uri])"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2014 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2015 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2016 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2017 Could be defined as:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2018 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2019 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2020 function Luan.do_file(uri)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2021 local fn = <a href="#Luan.load_file">Luan.load_file</a>(uri) or <a href="#Luan.error">Luan.error</a>("file '"..uri.."' not found")
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2022 return fn()
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2023 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2024 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2025 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2026 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2027 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2028 ["Luan.error"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2029 title = "Luan.error (message)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2030 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2031 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2032 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2033 Throws an error containing the message.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2034 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2035
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2036 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2037 Could be defined as:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2038 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2039 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2040 function Luan.error(message)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2041 <a href="#Luan.new_error">Luan.new_error</a>(message).throw()
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2042 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2043 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2044 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2045 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2046 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2047 ["Luan.eval"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2048 title = "Luan.eval (text [, source_name [, env]])"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2049 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2050 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2051 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2052 Evaluates <code>text</code> as a Luan expression.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2053 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2054
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2055 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2056 Could be defined as:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2057 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2058 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2059 function Luan.eval(text,source_name, env)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2060 return <a href="#Luan.load">Luan.load</a>( "return "..text, source_name or "eval", env )()
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2061 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2062 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2063 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2064 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2065 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2066 ["Luan.get_metatable"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2067 title = "Luan.get_metatable (table)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2068 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2069 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2070 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2071 If <code>table</code> does not have a metatable, returns <b>nil</b>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2072 Otherwise,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2073 if the table's metatable has a <code>"__metatable"</code> field,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2074 returns the associated value.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2075 Otherwise, returns the metatable of the given table.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2076 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2077 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2078 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2079 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2080 ["Luan.hash_code"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2081 title = "Luan.hash_code (v)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2082 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2083 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2084 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2085 Returns the hash code of <code>v</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2086 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2087 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2088 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2089 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2090 ["Luan.ipairs"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2091 title = "Luan.ipairs (t)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2092 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2093 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2094 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2095 Returns an iterator function
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2096 so that the construction
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2097 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2098 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2099 for i,v in ipairs(t) do <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2100 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2101
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2102 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2103 will iterate over the key&ndash;value pairs
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2104 (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2105 up to the first nil value.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2106 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2107
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2108 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2109 Could be defined as:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2110 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2111 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2112 function Luan.ipairs(t)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2113 local i = 0
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2114 return function()
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2115 if i < #t then
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2116 i = i + 1
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2117 return i, t[i]
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2118 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2119 end
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2120 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2121 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2122 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2123 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2124 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2125 ["Luan.load"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2126 title = "Luan.load (text, [source_name [, env [, persist]]])"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2127 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2128 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2129 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2130 Loads a chunk.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2131 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2132
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2133 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2134 The <code>text</code> is compiled.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2135 If there are no syntactic errors,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2136 returns the compiled chunk as a function;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2137 otherwise, throws an error.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2138 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2139
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2140 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2141 The <code>source_name</code> parameter is a string saying where the text came from. It is used to produce error messages. Defaults to "load".
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2142 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2143
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2144 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2145 If the <code>env</code> parameter is supplied, it becomes the <code>_ENV</code> of the chunk.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2146 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2147
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2148 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2149 The <code>persist</code> parameter is a boolean which determines if the compiled code is persistently cached to a temporary file. Defaults to <code>false</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2150 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2151 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2152 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2153 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2154 ["Luan.load_file"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2155 title = "Luan.load_file (file_uri)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2156 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2157 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2158 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2159 Similar to <a href="#Luan.load"><code>load</code></a>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2160 but gets the chunk from file <code>file_uri</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2161 <code>file_uri</code> can be a string or a uri table.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2162 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2163 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2164 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2165 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2166 ["Luan.new_error"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2167 title = "Luan.new_error (message)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2168 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2169 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2170 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2171 Creates a new error table containing the message assigned to "<code>message</code>". The error table also contains a <code>throw</code> function which throws the error. The table also contains a list of stack trace elements where each stack trace element is a table containing "<code>source</code>", "<code>line</code>", and possible "<code>call_to</code>". The table also has a metatable containing "<code>__to_string</code>" to render the error.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2172 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2173
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2174 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2175 To print the current stack trace, you could do:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2176 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2177 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2178 Io.print( Luan.new_error "stack" )
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2179 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2180 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2181 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2182 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2183 ["Luan.pairs"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2184 title = "Luan.pairs (t)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2185 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2186 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2187 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2188 If <code>t</code> has a metamethod <code>__pairs</code>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2189 calls it with <code>t</code> as argument and returns the
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2190 result from the call.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2191 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2192
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2193 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2194 Otherwise,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2195 returns a function
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2196 so that the construction
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2197 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2198 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2199 for k,v in pairs(t) do <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2200 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2201
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2202 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2203 will iterate over all key&ndash;value pairs of table <code>t</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2204 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2205 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2206 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2207 }
1813
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2208 ["Luan.parse"] = {
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2209 title = "Luan.parse (s)"
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2210 content = function()
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2211 %>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2212 <p>This Luan's equivalent to Javascript's JSON.parse(), but for a Luan value. In addition to the usual JSON values, Luan.parse allows long strings and allows specifying numeric types of <i>double</i>, <i>float</i>, <i>integer</i>, and <i>long</i>. For example:</p>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2213
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2214 <code block>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2215 local t = Luan.parse[=[
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2216 {
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2217 nothing = nil
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2218 t = true
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2219 f = false
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2220 s = "string"
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2221 ls = [[long string]]
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2222 n = 3
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2223 d = double(3)
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2224 f = float(3)
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2225 i = integer(3)
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2226 l = long(3)
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2227 list = { 1, 2, 3 }
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2228 table = {
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2229 one = 1
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2230 two = 2
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2231 three = 3
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2232 }
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2233 ["ugly-key"] = "something"
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2234 }
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2235 ]=]
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2236 </code>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2237 <%
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2238 end
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2239 }
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2240 ["Luan.range"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2241 title = "Luan.range (start, stop [, step])"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2242 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2243 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2244 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2245 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.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2246 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2247
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2248 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2249 Example use:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2250 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2251 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2252 for i in range(1,10) do
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2253 Io.print("count up:",i)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2254 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2255 for i in range(10,0,-1) do
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2256 Io.print("count down:",i)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2257 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2258 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2259
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2260 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2261 Could be defined as:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2262 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2263 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2264 function Luan.range(start, stop, step)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2265 step = step or 1
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2266 step == 0 and <a href="#Luan.error">Luan.error</a> "bad argument #3 (step may not be zero)"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2267 local i = start
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2268 return function()
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2269 if step > 0 and i <= stop or step < 0 and i >= stop then
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2270 local rtn = i
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2271 i = i + step
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2272 return rtn
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2273 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2274 end
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2275 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2276 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2277 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2278 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2279 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2280 ["Luan.raw_equal"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2281 title = "Luan.raw_equal (v1, v2)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2282 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2283 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2284 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2285 Checks whether <code>v1</code> is equal to <code>v2</code>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2286 without invoking any metamethod.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2287 Returns a boolean.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2288 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2289 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2290 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2291 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2292 ["Luan.raw_get"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2293 title = "Luan.raw_get (table, index)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2294 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2295 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2296 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2297 Gets the real value of <code>table[index]</code>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2298 without invoking any metamethod.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2299 <code>table</code> must be a table;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2300 <code>index</code> may be any value.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2301 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2302 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2303 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2304 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2305 ["Luan.raw_len"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2306 title = "Luan.raw_len (v)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2307 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2308 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2309 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2310 Returns the length of the object <code>v</code>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2311 which must be a table or a string,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2312 without invoking any metamethod.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2313 Returns an integer.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2314 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2315 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2316 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2317 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2318 ["Luan.raw_set"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2319 title = "Luan.raw_set (table, index, value)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2320 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2321 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2322 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2323 Sets the real value of <code>table[index]</code> to <code>value</code>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2324 without invoking any metamethod.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2325 <code>table</code> must be a table,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2326 <code>index</code> any value different from <b>nil</b>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2327 and <code>value</code> any Luan value.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2328 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2329 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2330 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2331 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2332 ["Luan.set_metatable"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2333 title = "Luan.set_metatable (table, metatable)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2334 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2335 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2336 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2337 Sets the metatable for the given table.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2338 If <code>metatable</code> is <b>nil</b>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2339 removes the metatable of the given table.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2340 If the original metatable has a <code>"__metatable"</code> field,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2341 raises an error.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2342 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2343 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2344 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2345 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2346 ["Luan.stringify"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2347 title = "Luan.stringify (v [,options])"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2348 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2349 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2350 <p>
1813
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2351 This Luan's equivalent to Javascript's JSON.stringify(), but for a Luan value.
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2352 <code>v</code> is a value of any type which is converted to a string that is a Luan expression. <code>options</code> may be a table or a function. If <code>options</code> is a table, it may contain the following flags whose <code>true</code> value means:
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2353 </p>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2354
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2355 <ul>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2356 <li><b>strict</b> - invalid types throw an error</li>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2357 <li><b>number_types</b> - numbers will be wrapped in functions for their type</li>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2358 <li><b>compressed</b> - eliminates white space</li>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2359 <li><b>inline</b> - on one line</li>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2360 <li><b>no_name_keys</b> - forces all keys to be of the form <code>["key"]</code></li>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2361 </ul>
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2362
fa0e73119b7c docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1812
diff changeset
2363 <p>If <code>options</code> is a function then this function should take an argument <code>stack</code> and return an <code>options</code> table. The <code>stack</code> will be a list of keys indicating where stringify is currently processing. This allows different options to be applied at different places in a data structure.</p>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2364 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2365 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2366 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2367 ["Luan.to_string"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2368 title = "Luan.to_string (v)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2369 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2370 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2371 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2372 Receives a value of any type and
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2373 converts it to a string in a human-readable format.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2374 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2375
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2376 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2377 If the metatable of <code>v</code> has a <code>"__to_string"</code> field,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2378 then <code>to_string</code> calls the corresponding value
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2379 with <code>v</code> as argument,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2380 and uses the result of the call as its result.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2381 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2382 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2383 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2384 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2385 ["Luan.type"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2386 title = "Luan.type (v)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2387 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2388 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2389 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2390 Returns the type of its only argument, coded as a string.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2391 The possible results of this function are
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2392 "<code>nil</code>" (a string, not the value <b>nil</b>),
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2393 "<code>number</code>",
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2394 "<code>string</code>",
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2395 "<code>binary</code>",
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2396 "<code>boolean</code>",
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2397 "<code>table</code>",
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2398 "<code>function</code>",
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2399 and "<code>java</code>".
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2400 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2401 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2402 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2403 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2404 ["Luan.values"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2405 title = "Luan.values (&middot;&middot;&middot;)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2406 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2407 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2408 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2409 Returns a function so that the construction
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2410 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2411 <pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2412 for i, v in Luan.values(&middot;&middot;&middot;) do <em>body</em> end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2413 </pre>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2414
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2415 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2416 will iterate over all values of <code>&middot;&middot;&middot;</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2417 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2418 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2419 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2420 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2421 ["Luan.VERSION"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2422 title = "Luan.VERSION"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2423 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2424 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2425 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2426 A global variable (not a function) that
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2427 holds a string containing the current Luan version.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2428 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2429 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2430 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2431 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2432 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2433 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2434 package_lib = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2435 title = "Modules"
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2436 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2437 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2438 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2439 Include this library by:
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2440 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2441 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2442 local Package = require "luan:Package.luan"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2443 </code>
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2444
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2445 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2446 The package library provides basic
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2447 facilities for loading modules in Luan.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2448 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2449 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2450 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2451 subs = {
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2452 ["Package.load"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2453 title = "Package.load (mod_uri)"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2454 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2455 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2456 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2457 Loads the given module.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2458 The function starts by looking into the <a href="#Package.loaded"><code>Package.loaded</code></a> table
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2459 to determine whether <code>mod_uri</code> is already loaded.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2460 If it is, then <code>Package.load</code> returns the value stored
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2461 at <code>Package.loaded[mod_uri]</code>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2462 Otherwise, it tries to load a new value for the module.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2463 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2464
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2465 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2466 To load a new value, <code>Package.load</code> first checks if <code>mod_uri</code> starts with "<b>java:</b>". If yes, then this is a Java class which is loaded by special Java code.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2467 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2468
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2469 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2470 Otherwise <code>Package.load</code> tries to read the text of the file referred to by <code>mod_uri</code>. If the file doesn't exist, then <code>Package.load</code> returns <b>false</b>. If the file exists, then its content is compiled into a chunk by calling <a href="#Luan.load"><code>Luan.load</code></a>. This chunk is run passing in <code>mod_uri</code> as an argument. The value returned by the chunk must not be <b>nil</b> and is loaded.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2471 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2472
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2473 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2474 If a new value for the module successful loaded, then it is stored in <code>Package.loaded[mod_uri]</code>. The value is returned.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2475 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2476 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2477 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2478 }
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2479 ["Package.loaded"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2480 title = "Package.loaded"
1667
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2481 content = function()
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2482 %>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2483 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2484 A table used by <a href="#Package.load"><code>Package.load</code></a> to control which
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2485 modules are already loaded.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2486 When you load a module <code>mod_uri</code> and
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2487 <code>Package.loaded[mod_uri]</code> is not <b>nil</b>,
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2488 <a href="#Package.load"><code>Package.load</code></a> simply returns the value stored there.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2489 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2490
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2491 <p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2492 This variable is only a reference to the real table;
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2493 assignments to this variable do not change the
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2494 table used by <a href="#Package.load"><code>Package.load</code></a>.
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2495 </p>
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2496 <%
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2497 end
c55373c3a0ce manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1660
diff changeset
2498 }
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2499 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2500 }
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2501 string_lib = {
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2502 title = "String Manipulation"
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2503 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2504 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2505 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2506 Include this library by:
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2507 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2508 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2509 local String = require "luan:String.luan"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2510 </code>
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2511
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2512 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2513 This library provides generic functions for string manipulation,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2514 such as finding and extracting substrings, and pattern matching.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2515 When indexing a string in Luan, the first character is at position&nbsp;1
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2516 (not at&nbsp;0, as in Java).
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2517 Indices are allowed to be negative and are interpreted as indexing backwards,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2518 from the end of the string.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2519 Thus, the last character is at position -1, and so on.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2520 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2521 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2522 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2523 subs = {
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2524 ["String.char"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2525 title = "String.char (&middot;&middot;&middot;)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2526 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2527 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2528 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2529 Receives zero or more integers.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2530 Returns a string with length equal to the number of arguments,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2531 in which each character has the internal numerical code equal
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2532 to its corresponding argument.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2533 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2534 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2535 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2536 }
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2537 ["String.contains"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2538 title = "String.contains (s, s2)"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2539 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2540 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2541 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2542 Returns a boolean indicating whether the <code>s</code> contains <code>s2</code>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2543 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2544 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2545 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2546 }
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2547 ["String.encode"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2548 title = "String.encode (s)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2549 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2550 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2551 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2552 Encodes argument <code>s</code> into a string that can be placed in quotes so as to return the original value of the string.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2553 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2554 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2555 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2556 }
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2557 ["String.ends_with"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2558 title = "String.ends_with (s, s2)"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2559 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2560 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2561 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2562 Returns a boolean indicating whether the <code>s</code> ends with <code>s2</code>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2563 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2564 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2565 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2566 }
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2567 ["String.find"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2568 title = "String.find (s, s2 [, init])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2569 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2570 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2571 <p>
1721
5c69d2e8bd75 no regex in String.find and String.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1719
diff changeset
2572 Looks for the first substring
5c69d2e8bd75 no regex in String.find and String.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1719
diff changeset
2573 <code>s2</code> in the string <code>s</code>.
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2574 If it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2575 where this occurrence starts and ends;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2576 otherwise, it returns <b>nil</b>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2577 A third, optional numerical argument <code>init</code> specifies
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2578 where to start the search;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2579 its default value is&nbsp;1 and can be negative.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2580 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2581
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2582 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2583 If the pattern has captures,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2584 then in a successful match
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2585 the captured values are also returned,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2586 after the two indices.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2587 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2588 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2589 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2590 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2591 ["String.format"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2592 title = "String.format (formatstring, &middot;&middot;&middot;)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2593 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2594 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2595 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2596 Returns a formatted version of its variable number of arguments
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2597 following the description given in its first argument (which must be a string).
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2598 The format string follows the same rules as the Java function <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object...)"><code>String.format</code></a> because Luan calls this internally.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2599 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2600
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2601 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2602 Note that Java's <code>String.format</code> is too stupid to convert between ints and floats, so you must provide the right kind of number.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2603 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2604 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2605 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2606 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2607 ["String.lower"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2608 title = "String.lower (s)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2609 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2610 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2611 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2612 Receives a string and returns a copy of this string with all
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2613 uppercase letters changed to lowercase.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2614 All other characters are left unchanged.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2615 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2616 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2617 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2618 }
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2619 ["String.regex"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2620 title = "String.regex (s)"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2621 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2622 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2623 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2624 Returns a <a href="#regex_table">regex</a> table for the pattern <code>s</code>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2625 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2626 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2627 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2628 }
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2629 ["String.regex_quote"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2630 title = "String.regex_quote (s)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2631 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2632 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2633 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2634 Returns a string which matches the literal string <code>s</code> in a regular expression. This function is simply the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#quote(java.lang.String)"><code>Pattern.quote</code></a>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2635 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2636 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2637 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2638 }
1718
5603ee8e2a71 rename String.rep to String.repeated
Franklin Schmidt <fschmidt@gmail.com>
parents: 1717
diff changeset
2639 ["String.repeated"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2640 title = "String.repeated (s, n [, sep])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2641 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2642 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2643 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2644 Returns a string that is the concatenation of <code>n</code> copies of
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2645 the string <code>s</code> separated by the string <code>sep</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2646 The default value for <code>sep</code> is the empty string
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2647 (that is, no separator).
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2648 Returns the empty string if <code>n</code> is not positive.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2649 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2650 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2651 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2652 }
1717
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2653 ["String.replace"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2654 title = "String.replace (s, target, replacement)"
1717
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2655 content = function()
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2656 %>
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2657 <p>
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2658 Returns a string where each substring <code>target</code> in <code>s</code> is replaced by <code>replacement</code>.
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2659 </p>
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2660 <%
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2661 end
c637a2a1023d add String.replace
Franklin Schmidt <fschmidt@gmail.com>
parents: 1716
diff changeset
2662 }
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2663 ["String.reverse"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2664 title = "String.reverse (s)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2665 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2666 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2667 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2668 Returns a string that is the string <code>s</code> reversed.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2669 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2670 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2671 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2672 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2673 ["String.split"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2674 title = "String.split (s, s2 [, limit])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2675 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2676 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2677 <p>
1721
5c69d2e8bd75 no regex in String.find and String.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1719
diff changeset
2678 Splits <code>s</code> using substring <code>s2</code> and returns the results. If <code>limit</code> is positive, then only returns at most that many results. If <code>limit</code> is zero, then remove trailing empty results.
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2679 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2680 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2681 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2682 }
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2683 ["String.starts_with"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2684 title = "String.starts_with (s, s2)"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2685 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2686 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2687 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2688 Returns a boolean indicating whether the <code>s</code> starts with <code>s2</code>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2689 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2690 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2691 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2692 }
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2693 ["String.sub"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2694 title = "String.sub (s, i [, j])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2695 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2696 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2697 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2698 Returns the substring of <code>s</code> that
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2699 starts at <code>i</code> and continues until <code>j</code>;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2700 <code>i</code> and <code>j</code> can be negative.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2701 If <code>j</code> is absent, then it is assumed to be equal to -1
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2702 (which is the same as the string length).
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2703 In particular,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2704 the call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2705 with length <code>j</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2706 and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2707 with length <code>i</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2708 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2709
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2710 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2711 If, after the translation of negative indices,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2712 <code>i</code> is less than 1,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2713 it is corrected to 1.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2714 If <code>j</code> is greater than the string length,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2715 it is corrected to that length.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2716 If, after these corrections,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2717 <code>i</code> is greater than <code>j</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2718 the function returns the empty string.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2719 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2720 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2721 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2722 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2723 ["String.to_binary"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2724 title = "String.to_binary (s)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2725 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2726 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2727 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2728 Converts a string to a binary by calling the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes()"><code>String.getBytes</code></a>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2729 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2730 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2731 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2732 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2733 ["String.to_number"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2734 title = "String.to_number (s [, base])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2735 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2736 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2737 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2738 When called with no <code>base</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2739 <code>to_number</code> tries to convert its argument to a number.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2740 If the argument is
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2741 a string convertible to a number,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2742 then <code>to_number</code> returns this number;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2743 otherwise, it returns <b>nil</b>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2744 The conversion of strings can result in integers or floats.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2745 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2746
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2747 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2748 When called with <code>base</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2749 then <code>s</code> must be a string to be interpreted as
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2750 an integer numeral in that base.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2751 In bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2752 represents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2753 with '<code>Z</code>' representing 35.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2754 If the string <code>s</code> is not a valid numeral in the given base,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2755 the function returns <b>nil</b>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2756 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2757 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2758 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2759 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2760 ["String.trim"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2761 title = "String.trim (s)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2762 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2763 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2764 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2765 Removes the leading and trailing whitespace by calling the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#trim()"><code>String.trim</code></a>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2766 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2767 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2768 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2769 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2770 ["String.unicode"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2771 title = "String.unicode (s [, i [, j]])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2772 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2773 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2774 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2775 Returns the internal numerical codes of the characters <code>s[i]</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2776 <code>s[i+1]</code>, ..., <code>s[j]</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2777 The default value for <code>i</code> is&nbsp;1;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2778 the default value for <code>j</code> is&nbsp;<code>i</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2779 These indices are corrected
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2780 following the same rules of function <a href="#String.sub"><code>String.sub</code></a>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2781 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2782 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2783 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2784 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2785 ["String.upper"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2786 title = "String.upper (s)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2787 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2788 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2789 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2790 Receives a string and returns a copy of this string with all
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2791 lowercase letters changed to uppercase.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2792 All other characters are left unchanged.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2793 The definition of what a lowercase letter is depends on the current locale.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2794 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2795 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2796 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2797 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2798 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
2799 }
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2800 regex_table = {
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2801 title = "Regular Expressions"
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2802 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2803 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2804 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2805 Regular expressions are handled using a regex table generated by <a href="#String.regex">String.regex</a>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2806 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2807
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2808 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2809 Pattern matching is based on the Java <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a> class.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2810 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2811 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2812 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2813 subs = {
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2814 ["regex.find"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2815 title = "regex.find (s [, init])"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2816 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2817 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2818 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2819 Looks for the first match of
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2820 the regex in the string <code>s</code>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2821 If it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2822 where this occurrence starts and ends;
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2823 otherwise, it returns <b>nil</b>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2824 A third, optional numerical argument <code>init</code> specifies
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2825 where to start the search;
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2826 its default value is&nbsp;1 and can be negative.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2827 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2828
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2829 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2830 If the regex has captures,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2831 then in a successful match
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2832 the captured values are also returned,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2833 after the two indices.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2834 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2835 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2836 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2837 }
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2838 ["regex.gmatch"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2839 title = "regex.gmatch (s)"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2840 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2841 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2842 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2843 Returns an iterator function that,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2844 each time it is called,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2845 returns the next captures from the regex
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2846 over the string <code>s</code>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2847 If the regex specifies no captures,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2848 then the whole match is produced in each call.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2849 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2850
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2851 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2852 As an example, the following loop
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2853 will iterate over all the words from string <code>s</code>,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2854 printing one per line:
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2855 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2856 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2857 local r = String.regex[[\w+]]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2858 local s = "hello world from Lua"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2859 for w in r.gmatch(s) do
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2860 print(w)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2861 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2862 </code>
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2863
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2864 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2865 The next example collects all pairs <code>key=value</code> from the
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2866 given string into a table:
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2867 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2868 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2869 local t = {}
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2870 local r = String.regex[[(\w+)=(\w+)]]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2871 local s = "from=world, to=Lua"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2872 for k, v in r.gmatch(s) do
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2873 t[k] = v
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2874 end
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2875 </code>
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2876
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2877 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2878 For this function, a caret '<code>^</code>' at the start of a pattern does not
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2879 work as an anchor, as this would prevent the iteration.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2880 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2881 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2882 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2883 }
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2884 ["regex.gsub"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2885 title = "regex.gsub (s, repl [, n])"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2886 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2887 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2888 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2889 Returns a copy of <code>s</code>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2890 in which all (or the first <code>n</code>, if given)
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2891 occurrences of the regex have been
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2892 replaced by a replacement string specified by <code>repl</code>,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2893 which can be a string, a table, or a function.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2894 <code>gsub</code> also returns, as its second value,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2895 the total number of matches that occurred.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2896 The name <code>gsub</code> comes from <em>Global SUBstitution</em>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2897 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2898
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2899 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2900 If <code>repl</code> is a string, then its value is used for replacement.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2901 The character&nbsp;<code>\</code> works as an escape character.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2902 Any sequence in <code>repl</code> of the form <code>$<em>d</em></code>,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2903 with <em>d</em> between 1 and 9,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2904 stands for the value of the <em>d</em>-th captured substring.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2905 The sequence <code>$0</code> stands for the whole match.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2906 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2907
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2908 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2909 If <code>repl</code> is a table, then the table is queried for every match,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2910 using the first capture as the key.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2911 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2912
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2913 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2914 If <code>repl</code> is a function, then this function is called every time a
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2915 match occurs, with all captured substrings passed as arguments,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2916 in order.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2917 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2918
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2919 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2920 In any case,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2921 if the regex specifies no captures,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2922 then it behaves as if the whole regex was inside a capture.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2923 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2924
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2925 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2926 If the value returned by the table query or by the function call
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2927 is not <b>nil</b>,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2928 then it is used as the replacement string;
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2929 otherwise, if it is <b>nil</b>,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2930 then there is no replacement
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2931 (that is, the original match is kept in the string).
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2932 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2933
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2934 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2935 Here are some examples:
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2936 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2937
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2938 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2939 local r = String.regex[[(\w+)]]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2940 local x = r.gsub("hello world", "$1 $1")
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2941 --&gt; x="hello hello world world"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2942
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2943 local r = String.regex[[(\w+)]]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2944 local x = r.gsub("hello world", "$0 $0", 1)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2945 --&gt; x="hello hello world"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2946
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2947 local r = String.regex[[(\w+)\s*(\w+)]]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2948 local x = r.gsub("hello world from Luan", "$2 $1")
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2949 --&gt; x="world hello Luan from"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2950
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2951 local r = String.regex[[\$(.*?)\$]]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2952 local x = r.gsub("4+5 = $return 4+5$", function(s)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2953 return load(s)()
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2954 end)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2955 --&gt; x="4+5 = 9"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2956
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2957 local r = String.regex[[\$(\w+)]]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2958 local t = {name="lua", version="5.3"}
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2959 local x = r.gsub("$name-$version.tar.gz", t)
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2960 --&gt; x="lua-5.3.tar.gz"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2961 </code>
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2962 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2963 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2964 }
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2965 ["regex.match"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2966 title = "regex.match (s [, init])"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2967 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2968 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2969 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2970 Looks for the first <em>match</em> of
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2971 the regex in the string <code>s</code>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2972 If it finds one, then <code>match</code> returns
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2973 the captures from the regex;
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2974 otherwise it returns <b>nil</b>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2975 If the regex specifies no captures,
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2976 then the whole match is returned.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2977 A third, optional numerical argument <code>init</code> specifies
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2978 where to start the search;
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2979 its default value is&nbsp;1 and can be negative.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2980 </p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2981 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2982 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2983 }
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2984 ["regex.matches"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2985 title = "regex.matches (s)"
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2986 content = function()
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2987 %>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2988 <p>
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2989 Returns a boolean indicating whether the regex can be found in string <code>s</code>.
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2990 This function is equivalent to
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2991 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2992 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2993 return regex.match(s) ~= nil
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2994 </code>
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2995 <%
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2996 end
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
2997 }
1719
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
2998 ["regex.set"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
2999 title = "regex.set (pattern)"
1719
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3000 content = function()
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3001 %>
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3002 <p>
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3003 Changes the regex pattern to <code>pattern</code>.
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3004 </p>
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3005 <%
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3006 end
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3007 }
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3008 ["regex.split"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3009 title = "regex.split (s [, limit])"
1719
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3010 content = function()
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3011 %>
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3012 <p>
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3013 Splits <code>s</code> using the regex and returns the results. If <code>limit</code> is positive, then only returns at most that many results. If <code>limit</code> is zero, then remove trailing empty results.
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3014 </p>
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3015 <%
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3016 end
2f3a8f16f583 add regex.split
Franklin Schmidt <fschmidt@gmail.com>
parents: 1718
diff changeset
3017 }
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
3018 }
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
3019 }
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3020 binary_lib = {
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3021 title = "Binary Manipulation"
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3022 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3023 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3024 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3025 Include this library by:
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3026 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3027 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3028 local Binary = require "luan:Binary.luan"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3029 </code>
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3030 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3031 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3032 subs = {
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3033 ["Binary.binary"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3034 title = "Binary.binary (&middot;&middot;&middot;)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3035 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3036 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3037 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3038 Receives zero or more bytes (as integers).
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3039 Returns a binary with length equal to the number of arguments,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3040 in which each byte has the internal numerical code equal
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3041 to its corresponding argument.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3042 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3043 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3044 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3045 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3046 ["Binary.byte"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3047 title = "Binary.byte (b [, i [, j]])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3048 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3049 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3050 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3051 Returns the internal numerical codes of the bytes <code>b[i]</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3052 <code>b[i+1]</code>, ..., <code>b[j]</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3053 The default value for <code>i</code> is&nbsp;1;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3054 the default value for <code>j</code> is&nbsp;<code>i</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3055 These indices are corrected
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3056 following the same rules of function <a href="#String.sub"><code>String.sub</code></a>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3057 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3058 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3059 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3060 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3061 ["Binary.to_string"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3062 title = "Binary.to_string (b [,charset])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3063 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3064 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3065 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3066 If <code>charset</code> is not nil then converts the binary <code>b</code> to a string using the Java <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#String(byte[],%20java.lang.String)">String constructor</a>, else makes each byte a char.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3067 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3068 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3069 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3070 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3071 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3072 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3073 table_lib = {
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3074 title = "Table Manipulation"
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3075 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3076 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3077 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3078 Include this library by:
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3079 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3080 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3081 local Table = require "luan:Table.luan"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3082 </code>
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3083
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3084 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3085 This library provides generic functions for table manipulation.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3086 It provides all its functions inside the table <code>Table</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3087 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3088 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3089 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3090 subs = {
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3091 ["Table.clear"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3092 title = "Table.clear (tbl)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3093 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3094 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3095 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3096 Clears the table.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3097 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3098 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3099 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3100 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3101 ["Table.concat"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3102 title = "Table.concat (list [, sep [, i [, j]]])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3103 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3104 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3105 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3106 Given a list,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3107 returns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3108 The default value for <code>sep</code> is the empty string,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3109 the default for <code>i</code> is 1,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3110 and the default for <code>j</code> is <code>#list</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3111 If <code>i</code> is greater than <code>j</code>, returns the empty string.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3112 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3113 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3114 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3115 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3116 ["Table.copy"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3117 title = "Table.copy (tbl [, i [, j]])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3118 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3119 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3120 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3121 If <code>i</code> is <code>nil</code>, returns a shallow copy of <code>tbl</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3122 Otherwise returns a new table which is a list of the elements <code>tbl[i] &middot;&middot;&middot; tbl[j]</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3123 By default, <code>j</code> is <code>#tbl</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3124 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3125 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3126 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3127 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3128 ["Table.insert"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3129 title = "Table.insert (list, pos, value)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3130 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3131 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3132 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3133 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3134 shifting up the elements
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3135 <code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3136 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3137 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3138 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3139 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3140 ["Table.is_empty"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3141 title = "Table.is_empty (tbl)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3142 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3143 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3144 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3145 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3146 }
1704
19df8abc9805 add Table.is_list
Franklin Schmidt <fschmidt@gmail.com>
parents: 1680
diff changeset
3147 ["Table.is_list"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3148 title = "Table.is_list (tbl)"
1704
19df8abc9805 add Table.is_list
Franklin Schmidt <fschmidt@gmail.com>
parents: 1680
diff changeset
3149 content = function()
19df8abc9805 add Table.is_list
Franklin Schmidt <fschmidt@gmail.com>
parents: 1680
diff changeset
3150 %>
19df8abc9805 add Table.is_list
Franklin Schmidt <fschmidt@gmail.com>
parents: 1680
diff changeset
3151 <%
19df8abc9805 add Table.is_list
Franklin Schmidt <fschmidt@gmail.com>
parents: 1680
diff changeset
3152 end
19df8abc9805 add Table.is_list
Franklin Schmidt <fschmidt@gmail.com>
parents: 1680
diff changeset
3153 }
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3154 ["Table.pack"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3155 title = "Table.pack (&middot;&middot;&middot;)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3156 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3157 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3158 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3159 Returns a new table with all parameters stored into keys 1, 2, etc.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3160 and with a field "<code>n</code>" with the total number of parameters.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3161 Note that the resulting table may not be a sequence.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3162 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3163 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3164 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3165 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3166 ["Table.remove"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3167 title = "Table.remove (list, pos)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3168 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3169 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3170 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3171 Removes from <code>list</code> the element at position <code>pos</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3172 returning the value of the removed element.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3173 When <code>pos</code> is an integer between 1 and <code>#list</code>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3174 it shifts down the elements
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3175 <code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3176 and erases element <code>list[#list]</code>;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3177 The index <code>pos</code> can also be 0 when <code>#list</code> is 0,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3178 or <code>#list + 1</code>;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3179 in those cases, the function erases the element <code>list[pos]</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3180 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3181 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3182 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3183 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3184 ["Table.size"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3185 title = "Table.size (tbl)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3186 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3187 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3188 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3189 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3190 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3191 ["Table.sort"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3192 title = "Table.sort (list [, comp])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3193 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3194 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3195 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3196 Sorts list elements in a given order, <em>in-place</em>,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3197 from <code>list[1]</code> to <code>list[#list]</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3198 If <code>comp</code> is given,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3199 then it must be a function that receives two list elements
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3200 and returns true when the first element must come
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3201 before the second in the final order
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3202 (so that <code>not comp(list[i+1],list[i])</code> will be true after the sort).
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3203 If <code>comp</code> is not given,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3204 then the standard Lua operator <code>&lt;</code> is used instead.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3205 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3206
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3207 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3208 The sort algorithm is not stable;
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3209 that is, elements considered equal by the given order
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3210 may have their relative positions changed by the sort.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3211 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3212 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3213 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3214 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3215 ["Table.unpack"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3216 title = "Table.unpack (list [, i [, j]])"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3217 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3218 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3219 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3220 Returns the elements from the given list.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3221 This function is equivalent to
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3222 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3223 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3224 return list[i], list[i+1], &middot;&middot;&middot;, list[j]
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3225 </code>
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3226
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3227 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3228 By default, <code>i</code> is 1 and <code>j</code> is <code>list.n or #list</code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3229 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3230 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3231 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3232 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3233 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3234 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3235 number_lib = {
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3236 title = "Number Manipulation"
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3237 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3238 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3239 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3240 Include this library by:
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3241 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3242 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3243 local Number = require "luan:Number.luan"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3244 </code>
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3245 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3246 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3247 subs = {
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3248 ["Number.double"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3249 title = "Number.double (x)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3250 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3251 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3252 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3253 Returns <code>x</code> as a double.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3254 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3255 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3256 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3257 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3258 ["Number.float"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3259 title = "Number.float (x)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3260 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3261 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3262 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3263 Returns <code>x</code> as a float.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3264 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3265 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3266 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3267 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3268 ["Number.integer"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3269 title = "Number.integer (x)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3270 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3271 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3272 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3273 If the value <code>x</code> is convertible to an integer,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3274 returns that integer.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3275 Otherwise throws an error.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3276 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3277 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3278 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3279 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3280 ["Number.long"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3281 title = "Number.long (x)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3282 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3283 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3284 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3285 If the value <code>x</code> is convertible to an long,
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3286 returns that long.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3287 Otherwise throws an error.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3288 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3289 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3290 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3291 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3292 ["Number.long_to_string"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3293 title = "Number.long_to_string (i, radix)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3294 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3295 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3296 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3297 Converts long value <code>i</code> to a string by calling <code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#toString(long,%20int)">Long.toString</a></code>.
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3298 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3299 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3300 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3301 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3302 ["Number.type"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3303 title = "Number.type (x)"
1668
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3304 content = function()
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3305 %>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3306 <p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3307 Returns a string for the numeric type of <code>x</code>. Possible return values include "<code>integer</code>", "<code>long</code>", "<code>double</code>", and "<code>float</code>".
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3308 </p>
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3309 <%
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3310 end
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3311 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3312 }
ef75d9ad5ce9 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1667
diff changeset
3313 }
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3314 math_lib = {
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3315 title = "Mathematical Functions"
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3316 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3317 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3318 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3319 Include this library by:
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3320 </p>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3321 <code block>
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3322 local Math = require "luan:Math.luan"
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3323 </code>
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3324
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3325 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3326 This library provides basic mathematical functions.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3327 It provides all its functions and constants inside the table <code>Math</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3328 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3329 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3330 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3331 subs = {
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3332 ["Math.abs"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3333 title = "Math.abs (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3334 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3335 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3336 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3337 Returns the absolute value of <code>x</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3338 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3339 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3340 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3341 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3342 ["Math.acos"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3343 title = "Math.acos (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3344 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3345 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3346 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3347 Returns the arc cosine of <code>x</code> (in radians).
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3348 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3349 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3350 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3351 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3352 ["Math.asin"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3353 title = "Math.asin (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3354 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3355 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3356 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3357 Returns the arc sine of <code>x</code> (in radians).
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3358 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3359 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3360 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3361 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3362 ["Math.atan"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3363 title = "Math.atan (y, x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3364 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3365 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3366 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3367 Returns the arc tangent of <code>y/x</code> (in radians),
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3368 but uses the signs of both parameters to find the
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3369 quadrant of the result.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3370 (It also handles correctly the case of <code>x</code> being zero.)
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3371 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3372 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3373 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3374 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3375 ["Math.ceil"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3376 title = "Math.ceil (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3377 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3378 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3379 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3380 Returns the smallest integral value larger than or equal to <code>x</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3381 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3382 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3383 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3384 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3385 ["Math.cos"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3386 title = "Math.cos (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3387 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3388 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3389 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3390 Returns the cosine of <code>x</code> (assumed to be in radians).
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3391 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3392 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3393 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3394 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3395 ["Math.deg"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3396 title = "Math.deg (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3397 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3398 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3399 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3400 Converts the angle <code>x</code> from radians to degrees.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3401 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3402 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3403 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3404 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3405 ["Math.exp"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3406 title = "Math.exp (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3407 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3408 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3409 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3410 Returns the value <em>e<sup>x</sup></em>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3411 (where <code>e</code> is the base of natural logarithms).
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3412 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3413 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3414 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3415 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3416 ["Math.floor"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3417 title = "Math.floor (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3418 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3419 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3420 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3421 Returns the largest integral value smaller than or equal to <code>x</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3422 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3423 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3424 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3425 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3426 ["Math.fmod"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3427 title = "Math.fmod (x, y)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3428 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3429 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3430 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3431 Returns the remainder of the division of <code>x</code> by <code>y</code>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3432 that rounds the quotient towards zero.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3433 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3434 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3435 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3436 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3437 ["Math.huge"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3438 title = "Math.huge"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3439 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3440 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3441 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3442 A value larger than any other numerical value.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3443 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3444 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3445 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3446 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3447 ["Math.log"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3448 title = "Math.log (x [, base])"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3449 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3450 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3451 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3452 Returns the logarithm of <code>x</code> in the given base.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3453 The default for <code>base</code> is <em>e</em>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3454 (so that the function returns the natural logarithm of <code>x</code>).
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3455 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3456 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3457 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3458 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3459 ["Math.max"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3460 title = "Math.max (x, &middot;&middot;&middot;)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3461 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3462 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3463 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3464 Returns the argument with the maximum value,
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3465 according to the Lua operator <code>&lt;</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3466 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3467 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3468 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3469 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3470 ["Math.max_integer"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3471 title = "Math.max_integer"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3472 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3473 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3474 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3475 An integer with the maximum value for an integer.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3476 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3477 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3478 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3479 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3480 ["Math.min"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3481 title = "Math.min (x, &middot;&middot;&middot;)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3482 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3483 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3484 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3485 Returns the argument with the minimum value,
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3486 according to the Lua operator <code>&lt;</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3487 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3488 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3489 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3490 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3491 ["Math.min_integer"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3492 title = "Math.min_integer"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3493 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3494 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3495 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3496 An integer with the minimum value for an integer.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3497 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3498 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3499 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3500 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3501 ["Math.modf"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3502 title = "Math.modf (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3503 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3504 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3505 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3506 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3507 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3508 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3509 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3510 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3511 ["Math.pi"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3512 title = "Math.pi"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3513 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3514 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3515 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3516 The value of <em>&pi;</em>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3517 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3518 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3519 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3520 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3521 ["Math.rad"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3522 title = "Math.rad (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3523 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3524 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3525 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3526 Converts the angle <code>x</code> from degrees to radians.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3527 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3528 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3529 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3530 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3531 ["Math.random"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3532 title = "Math.random ([m [, n])"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3533 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3534 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3535 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3536 When called without arguments,
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3537 returns a pseudo-random float with uniform distribution
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3538 in the range <em>[0,1)</em>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3539 When called with two integers <code>m</code> and <code>n</code>,
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3540 <code>Math.random</code> returns a pseudo-random integer
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3541 with uniform distribution in the range <em>[m, n]</em>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3542 (The value <em>m-n</em> cannot be negative and must fit in a Luan integer.)
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3543 The call <code>Math.random(n)</code> is equivalent to <code>Math.random(1,n)</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3544 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3545
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3546 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3547 This function is an interface to the underling
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3548 pseudo-random generator function provided by Java.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3549 No guarantees can be given for its statistical properties.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3550 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3551 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3552 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3553 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3554 ["Math.sin"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3555 title = "Math.sin (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3556 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3557 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3558 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3559 Returns the sine of <code>x</code> (assumed to be in radians).
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3560 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3561 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3562 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3563 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3564 ["Math.sqrt"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3565 title = "Math.sqrt (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3566 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3567 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3568 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3569 Returns the square root of <code>x</code>.
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3570 (You can also use the expression <code>x^0.5</code> to compute this value.)
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3571 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3572 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3573 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3574 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3575 ["Math.tan"] = {
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3576 title = "Math.tan (x)"
1669
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3577 content = function()
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3578 %>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3579 <p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3580 Returns the tangent of <code>x</code> (assumed to be in radians).
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3581 </p>
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3582 <%
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3583 end
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3584 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3585 }
fdeb1879fe02 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1668
diff changeset
3586 }
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3587 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3588 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3589 }
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3590
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3591
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3592 return function()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3593 Io.stdout = Http.response.text_writer()
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3594 %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3595 <!doctype html>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3596 <html>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3597 <head>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3598 <% head() %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3599 <title>Luan Reference Manual</title>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3600 <style>
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3601 p[list] {
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3602 font-family: monospace;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3603 margin-left: 40px;
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3604 }
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3605 p[list] span {
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3606 display: inline-block;
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3607 }
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3608 p[list=keywords] {
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3609 max-width: 700px;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3610 }
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3611 p[list=keywords] span {
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3612 width: 100px;
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3613 }
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3614 p[list=tokens] {
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3615 max-width: 400px;
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
3616 }
1812
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3617 p[list=tokens] span {
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3618 width: 50px;
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3619 }
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3620 li[c_libs] li li > a {
f44dcb3fedf7 docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents: 1797
diff changeset
3621 font-family: monospace;
1716
b82767112d8e add String.regex
Franklin Schmidt <fschmidt@gmail.com>
parents: 1704
diff changeset
3622 }
1656
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3623 </style>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3624 </head>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3625 <body>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3626 <% docs_header() %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3627 <div content>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3628 <h1><a href="manual.html">Luan Reference Manual</a></h1>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3629 <p small>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3630 Original copyright &copy; 2015 Lua.org, PUC-Rio.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3631 Freely available under the terms of the
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3632 <a href="http://www.lua.org/license.html">Lua license</a>.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3633 Modified for Luan.
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3634 </p>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3635 <hr>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3636 <h2>Contents</h2>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3637 <div toc>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3638 <% show_toc(content) %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3639 </div>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3640 <hr>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3641 <% show_content(content,2) %>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3642 </div>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3643 </body>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3644 </html>
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3645 <%
540bf2343078 manual work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3646 end