Mercurial Hosting > luan
comparison website/src/diff.html @ 1327:b29eefad2111
website - improve docs
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 08 Feb 2019 00:45:31 -0700 |
parents | 29d6d7d79c41 |
children | f5368cd8c056 |
comparison
equal
deleted
inserted
replaced
1326:29d6d7d79c41 | 1327:b29eefad2111 |
---|---|
11 <div small> | 11 <div small> |
12 <a href=".">Luan</a> | 12 <a href=".">Luan</a> |
13 / <a href="docs.html">Documentation</a> | 13 / <a href="docs.html">Documentation</a> |
14 </div> | 14 </div> |
15 | 15 |
16 <h1>How Luan differs from Lua</h1> | 16 <h1><a href="diff.html">How Luan differs from Lua</a></h1> |
17 | 17 |
18 <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> | 18 <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> |
19 | 19 |
20 <hr/> | 20 <hr/> |
21 | 21 |
64 </ul> | 64 </ul> |
65 </div> | 65 </div> |
66 | 66 |
67 <hr/> | 67 <hr/> |
68 | 68 |
69 <h2 heading><a name="intro">Introduction</a></h2> | 69 <h2 heading><a name="intro" href="#intro">Introduction</a></h2> |
70 | 70 |
71 <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> | 71 <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> |
72 | 72 |
73 <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p> | 73 <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p> |
74 | 74 |
75 <h2 heading><a name="basic">Basic Concepts</a></h2> | 75 <h2 heading><a name="basic" href="#basic">Basic Concepts</a></h2> |
76 | 76 |
77 <h3 heading><a name="types">Values and Types</a></h3> | 77 <h3 heading><a name="types" href="#types">Values and Types</a></h3> |
78 | 78 |
79 <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> | 79 <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> |
80 | 80 |
81 <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> | 81 <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> |
82 | 82 |
86 | 86 |
87 <p>The Luan <em>binary</em> type is the Java <em>byte[ ]</em> type which is an array of bytes.</p> | 87 <p>The Luan <em>binary</em> type is the Java <em>byte[ ]</em> type which is an array of bytes.</p> |
88 | 88 |
89 <p>The Luan <em>table</em> type is just like its Lua equivalent, but implemented in Java.</p> | 89 <p>The Luan <em>table</em> type is just like its Lua equivalent, but implemented in Java.</p> |
90 | 90 |
91 <h3 heading><a name="env">Environments</a></h3> | 91 <h3 heading><a name="env" href="#env">Environments</a></h3> |
92 | 92 |
93 <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> | 93 <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> |
94 | 94 |
95 <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> | 95 <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> |
96 | 96 |
97 <h3 heading><a name="error">Error Handling</a></h3> | 97 <h3 heading><a name="error" href="#error">Error Handling</a></h3> |
98 | 98 |
99 <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> | 99 <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> |
100 | 100 |
101 <h3 heading><a name="meta">Metatables and Metamethods</a></h3> | 101 <h3 heading><a name="meta" href="#meta">Metatables and Metamethods</a></h3> |
102 | 102 |
103 <p>Luan only has metatable for tables, not for other types.</p> | 103 <p>Luan only has metatable for tables, not for other types.</p> |
104 | 104 |
105 <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> | 105 <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> |
106 | 106 |
107 <h3 heading><a name="gc">Garbage Collection</a></h3> | 107 <h3 heading><a name="gc" href="#gc">Garbage Collection</a></h3> |
108 | 108 |
109 <p>Luan uses Java garbage collection. Luan has no special garbage collection methods.</p> | 109 <p>Luan uses Java garbage collection. Luan has no special garbage collection methods.</p> |
110 | 110 |
111 <p>Luan does not yet have weak tables but this will be added.</p> | 111 <p>Luan does not yet have weak tables but this will be added.</p> |
112 | 112 |
113 <h3 heading><a name="coroutines">Coroutines</a></h3> | 113 <h3 heading><a name="coroutines" href="#coroutines">Coroutines</a></h3> |
114 | 114 |
115 <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> | 115 <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> |
116 | 116 |
117 <h2 heading><a name="lang">The Language</a></h2> | 117 <h2 heading><a name="lang" href="#lang">The Language</a></h2> |
118 | 118 |
119 <h3 heading><a name="lex">Lexical Conventions</a></h3> | 119 <h3 heading><a name="lex" href="#lex">Lexical Conventions</a></h3> |
120 | 120 |
121 <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> | 121 <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> |
122 | 122 |
123 <p>Luan has exactly the same set of keywords as Lua and has the same other lexical conventions.</p> | 123 <p>Luan has exactly the same set of keywords as Lua and has the same other lexical conventions.</p> |
124 | 124 |
125 <h3 heading><a name="vars">Variables</a></h3> | 125 <h3 heading><a name="vars" href="#vars">Variables</a></h3> |
126 | 126 |
127 <p> | 127 <p> |
128 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. | 128 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. |
129 | 129 |
130 <h3 heading><a name="stmt">Statements</a></h3> | 130 <h3 heading><a name="stmt" href="#stmt">Statements</a></h3> |
131 | 131 |
132 <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> | 132 <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> |
133 | 133 |
134 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p> | 134 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p> |
135 | 135 |
136 <h4 heading><a name="control">Control Structures</a></h4> | 136 <h4 heading><a name="control" href="#control">Control Structures</a></h4> |
137 | 137 |
138 <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> | 138 <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> |
139 | 139 |
140 <p>Luan does not have a <b>goto</b> statement.</p> | 140 <p>Luan does not have a <b>goto</b> statement.</p> |
141 | 141 |
142 <h4 heading><a name="for">For Statement</a></h4> | 142 <h4 heading><a name="for" href="#for">For Statement</a></h4> |
143 | 143 |
144 <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> | 144 <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> |
145 | 145 |
146 <pre> | 146 <pre> |
147 for i in range(from,to,step) do <em>block</em> end | 147 for i in range(from,to,step) do <em>block</em> end |
164 block | 164 block |
165 end | 165 end |
166 end | 166 end |
167 </pre> | 167 </pre> |
168 | 168 |
169 <h4 heading><a name="logical">Logical Statements</a></h4> | 169 <h4 heading><a name="logical" href="#logical">Logical Statements</a></h4> |
170 | 170 |
171 <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> | 171 <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> |
172 | 172 |
173 <pre> | 173 <pre> |
174 x==5 or error "x should be 5" | 174 x==5 or error "x should be 5" |
175 </pre> | 175 </pre> |
176 | 176 |
177 <h4 heading><a name="template_stmt">Template Statements</a></h4> | 177 <h4 heading><a name="template_stmt" href="#template_stmt">Template Statements</a></h4> |
178 | 178 |
179 <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> | 179 <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> |
180 | 180 |
181 | 181 |
182 <h3 heading><a name="expr">Expressions</a></h3> | 182 <h3 heading><a name="expr" href="#expr">Expressions</a></h3> |
183 | 183 |
184 <h4 heading><a name="conversions">Coercions and Conversions</a></h4> | 184 <h4 heading><a name="conversions" href="#conversions">Coercions and Conversions</a></h4> |
185 | 185 |
186 <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p> | 186 <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p> |
187 | 187 |
188 <h4 heading><a name="bit">Bitwise Operators</a></h4> | 188 <h4 heading><a name="bit" href="#bit">Bitwise Operators</a></h4> |
189 | 189 |
190 <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> | 190 <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> |
191 | 191 |
192 <h4 heading><a name="logical_ops">Logical Operators</a></h4> | 192 <h4 heading><a name="logical_ops" href="#logical_ops">Logical Operators</a></h4> |
193 | 193 |
194 <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> | 194 <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> |
195 | 195 |
196 <h4 heading><a name="concatenation">Concatenation</a></h4> | 196 <h4 heading><a name="concatenation" href="#concatenation">Concatenation</a></h4> |
197 | 197 |
198 <p>Unlike Lua, Luan converts all concatenation operands to strings. | 198 <p>Unlike Lua, Luan converts all concatenation operands to strings. |
199 | 199 |
200 <h4 heading><a name="constructors">Table Constructors</a></h4> | 200 <h4 heading><a name="constructors" href="#constructors">Table Constructors</a></h4> |
201 | 201 |
202 <p>Unlike Lua, Luan considers an <b>end_of_line</b> to be a field separator in a table constructor.</p> | 202 <p>Unlike Lua, Luan considers an <b>end_of_line</b> to be a field separator in a table constructor.</p> |
203 | 203 |
204 <h4 heading><a name="fn_calls">Function Calls</a></h4> | 204 <h4 heading><a name="fn_calls" href="#fn_calls">Function Calls</a></h4> |
205 | 205 |
206 <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> | 206 <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> |
207 | 207 |
208 <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> | 208 <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> |
209 | 209 |
210 <p>Luan doesn't support <em>proper tail calls</em>. Because Java doesn't support this cleanly, this was left out.</p> | 210 <p>Luan doesn't support <em>proper tail calls</em>. Because Java doesn't support this cleanly, this was left out.</p> |
211 | 211 |
212 <h4 heading><a name="template_expr">Template Expressions</a></h4> | 212 <h4 heading><a name="template_expr" href="#template_expr">Template Expressions</a></h4> |
213 | 213 |
214 <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> | 214 <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> |
215 | 215 |
216 </body> | 216 </body> |
217 </html> | 217 </html> |