comparison website/src/diff.html @ 1325:28c1fc6d9d29

website - make docs html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 07 Feb 2019 23:00:20 -0700
parents website/src/diff.html.luan@1660136ac451
children 29d6d7d79c41
comparison
equal deleted inserted replaced
1324:1660136ac451 1325:28c1fc6d9d29
1 <!doctype html>
2 <html>
3 <head>
4 <title>How Luan differs from Lua</title>
5 <style>
6 @import "/site.css";
7 </style>
8 </head>
9 <body>
10
11 <div small><a href="/">Luan</a></div>
12
13 <h1>How Luan differs from Lua</h1>
14
15 <p>This document explains how Luan differs from <a href="http://www.lua.org">Lua</a> as described in the <a href="http://www.lua.org/manual/5.3/">Lua 5.3 Reference Manual</a>.</p>
16
17 <hr/>
18
19 <h2>Contents</h2>
20
21 <div contents><a href="#intro">Introduction</a></div>
22
23 <div contents>
24 <a href="#basic">Basic Concepts</a>
25 <ul>
26 <li><a href="#types">Values and Types</a></li>
27 <li><a href="#env">Environments</a></li>
28 <li><a href="#error">Error Handling</a></li>
29 <li><a href="#meta">Metatables and Metamethods</a></li>
30 <li><a href="#gc">Garbage Collection</a></li>
31 <li><a href="#coroutines">Coroutines</a></li>
32 </ul>
33 </div>
34
35 <div contents>
36 <a href="#lang">The Language</a>
37 <ul>
38 <li><a href="#lex">Lexical Conventions</a></li>
39 <li><a href="#vars">Variables</a></li>
40 <li>
41 <a href="#stmt">Statements</a>
42 <ul>
43 <li><a href="#control">Control Structures</a></li>
44 <li><a href="#for">For Statement</a></li>
45 <li><a href="#logical">Logical Statements</a></li>
46 <li><a href="#template_stmt">Template Statements</a></li>
47 </ul>
48 </li>
49 <li>
50 <a href="#expr">Expressions</a>
51 <ul>
52 <li><a href="#conversions">Coercions and Conversions</a></li>
53 <li><a href="#bit">Bitwise Operators</a></li>
54 <li><a href="#logical_ops">Logical Operators</a></li>
55 <li><a href="#concatenation">Concatenation</a></li>
56 <li><a href="#constructors">Table Constructors</a></li>
57 <li><a href="#fn_calls">Function Calls</a></li>
58 <li><a href="#template_expr">Template Expressions</a></li>
59 </ul>
60 </li>
61 </ul>
62 </div>
63
64 <hr/>
65
66 <h2 heading><a name="intro">Introduction</a></h2>
67
68 <p>Lua is one of the simplest languages available, but Luan is even simpler. This means Luan removes more than it adds. Most of what is added is added in the library, not in the language itself.</p>
69
70 <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p>
71
72 <h2 heading><a name="basic">Basic Concepts</a></h2>
73
74 <h3 heading><a name="types">Values and Types</a></h3>
75
76 <p>Luan does not have the Lua <em>thread</em> type. Luan adds a <em>binary</em> type that Lua doesn't have. This is because Lua strings can represent binary while Luan strings cannot.</p>
77
78 <p>The Luan <em>Nil</em> type is implemented as the Java <em>null</em>. The Luan <em>Boolean</em> type is implemented as the Java <em>Boolean</em> type. The Luan <em>Number</em> type is implemented as the Java <em>Number</em> type. The Luan <em>String</em> type is implemented as the Java <em>String</em> type. Actual numbers may be any subclass of the Java <em>Number</em> class.</p>
79
80 <p>Luan functions may be written in Luan or may be wrappers around native Java methods. Any Java method may be called as a Luan function.</p>
81
82 <p>The Luan <em>java</em> type is a replacement for Lua's <em>userdata</em>. A Luan <em>java</em> value is nothing more than a Java object that doesn't fall into one of the other recognized types.</p>
83
84 <p>The Luan <em>binary</em> type is the Java <em>byte[ ]</em> type which is an array of bytes.</p>
85
86 <p>The Luan <em>table</em> type is just like its Lua equivalent, but implemented in Java.</p>
87
88 <h3 heading><a name="env">Environments</a></h3>
89
90 <p>Luan has no global environment at all, no <code>_G</code>. By default, Luan doesn't define <code>_ENV</code> either, but if you define it as a local table in a chunk, then it acts like it does in Lua. When <code>_ENV</code> isn't defined, there are no global variables and an unrecognized variable name produces a compile error.</p>
91
92 <p>Every module is initialized with two local functions: <code>require</code> and <code>java</code>. The module then uses these functions to get access to whatever else it needs.</p>
93
94 <h3 heading><a name="error">Error Handling</a></h3>
95
96 <p>Luan has the functions <code>error</code> and <code>pcall</code> but does not have <code>xpcall</code>. Luan adds the function <code>try</code> which looks and acts like try-catch blocks in other languages. Luan errors are implemented as an error table, not as a message object.</p>
97
98 <h3 heading><a name="meta">Metatables and Metamethods</a></h3>
99
100 <p>Luan only has metatable for tables, not for other types.</p>
101
102 <p>Luan does not support the <b>call</b> metamethod. There is nothing that one can do with the <b>call</b> metamethod that can't be done more cleanly with closures, so this was left out.</p>
103
104 <h3 heading><a name="gc">Garbage Collection</a></h3>
105
106 <p>Luan uses Java garbage collection. Luan has no special garbage collection methods.</p>
107
108 <p>Luan does not yet have weak tables but this will be added.</p>
109
110 <h3 heading><a name="coroutines">Coroutines</a></h3>
111
112 <p>Luan does not have coroutines. Coroutines is a complex concept that isn't needed in a simple language, so it was left out.</p>
113
114 <h2 heading><a name="lang">The Language</a></h2>
115
116 <h3 heading><a name="lex">Lexical Conventions</a></h3>
117
118 <p>Unlike Lua, 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.</p>
119
120 <p>Luan has exactly the same set of keywords as Lua and has the same other lexical conventions.</p>
121
122 <h3 heading><a name="vars">Variables</a></h3>
123
124 <p>
125 By default, there are no global variables and an undefined variable produces a compile error. To enable global variables, one must define <code>_ENV</code>. Avoiding global variables makes it much easier to catch errors at compile time.
126
127 <h3 heading><a name="stmt">Statements</a></h3>
128
129 <p>Luan adds the block terminators <b>end_do</b>, <b>end_for</b>, <b>end_function</b>, <b>end_if</b>, and <b>end_while</b>. These can be used to end the appropriate block type, but <b>end</b> can also be used to end any block.</p>
130
131 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p>
132
133 <h4 heading><a name="control">Control Structures</a></h4>
134
135 <p>The Luan <b>if</b>, <b>while</b>, and <b>repeat</b> statement are the same as in Lua except that the condition expression must return a boolean value. Any other value type will produce an error. This helps catch errors and makes code more readable.</p>
136
137 <p>Luan does not have a <b>goto</b> statement.</p>
138
139 <h4 heading><a name="for">For Statement</a></h4>
140
141 <p>Luan has no numeric <b>for</b> statement. Luan only has generic <b>for</b> statement. Instead of the numeric <b>for</b> statement, Luan uses the <code>range</code> function in a generic <b>for</b> statement like this:</p>
142
143 <pre>
144 for i in range(from,to,step) do <em>block</em> end
145 </pre>
146
147 <p>The Luan generic <b>for</b> statement is simpler than the Lua version because Luan only uses an expression, not an explist. So a <b>for</b> statement like:</p>
148
149 <pre>
150 for var_1, &middot;&middot;&middot;, var_n in exp do block end
151 </pre>
152
153 <p>is equivalent to the code:</p>
154
155 <pre>
156 do
157 local f = exp
158 while true do
159 local var_1, &middot;&middot;&middot;, var_n = f()
160 if var_1 == nil then break end
161 block
162 end
163 end
164 </pre>
165
166 <h4 heading><a name="logical">Logical Statements</a></h4>
167
168 <p>Unlike Lua, Luan allows <b>or</b> and <b>and</b> expressions to be stand-alone statements. This is useful in cases like this:</p>
169
170 <pre>
171 x==5 or error "x should be 5"
172 </pre>
173
174 <h4 heading><a name="template_stmt">Template Statements</a></h4>
175
176 <p>Template statements are a Luan addition that don't exist in Lua. See <a href="manual.html#template_stmt">Template Statements</a> in the Luan Reference Manual.</p>
177
178
179 <h3 heading><a name="expr">Expressions</a></h3>
180
181 <h4 heading><a name="conversions">Coercions and Conversions</a></h4>
182
183 <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p>
184
185 <h4 heading><a name="bit">Bitwise Operators</a></h4>
186
187 <p>Bitwise operators appear to be a new addition to Lua 5.3 and didn't exist in Lua 5.2. Luan does not support bitwise operators, but these can be added if there is a need.</p>
188
189 <h4 heading><a name="logical_ops">Logical Operators</a></h4>
190
191 <p>The only change in Luan is that <b>not</b> must take a boolean argument. This helps catch errors and makes code more readable.</p>
192
193 <h4 heading><a name="concatenation">Concatenation</a></h4>
194
195 <p>Unlike Lua, Luan converts all concatenation operands to strings.
196
197 <h4 heading><a name="constructors">Table Constructors</a></h4>
198
199 <p>Unlike Lua, Luan considers an <b>end_of_line</b> to be a field separator in a table constructor.</p>
200
201 <h4 heading><a name="fn_calls">Function Calls</a></h4>
202
203 <p>Unlike Lua, Luan does not allow extra non-nil arguments to be passed to a function. In Luan, this causes an error. This change helps find coding mistakes that would be very hard to detect otherwise.</p>
204
205 <p>Luan does not support Lua's <code>v:name(args)</code> style object-oriented function call. Object oriented programming is done in Luan using closures, so this feature is not needed.</p>
206
207 <p>Luan doesn't support <em>proper tail calls</em>. Because Java doesn't support this cleanly, this was left out.</p>
208
209 <h4 heading><a name="template_expr">Template Expressions</a></h4>
210
211 <p>Template expressions are a Luan addition that don't exist in Lua. See <a href="manual.html#template_expr">Template Expressions</a> in the Luan Reference Manual.</p>
212
213 </body>
214 </html>