comparison website/src/diff.html.luan @ 562:7cc9d4a53d3b

remove SimplyHTML from documentation
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 24 Jun 2015 14:20:00 -0600
parents 0dfc01d8d42d
children b73f005f3735
comparison
equal deleted inserted replaced
561:363d07e26549 562:7cc9d4a53d3b
1 local Io = require "luan:Io" 1 local Io = require "luan:Io"
2 local Html = require "luan:Html"
3 local Http = require "luan:http/Http" 2 local Http = require "luan:http/Http"
4 local Shared = require "site:/Shared" 3 local Shared = require "site:/Shared"
5 local Manual = require "site:/manual.html"
6 local heading_options = Shared.heading_options
7 4
8 5
9 return function() 6 return function()
10 Io.stdout = Http.response.text_writer() 7 Io.stdout = Http.response.text_writer()
11 %> 8 %>
12 <html> 9 <html>
13 <head> 10 <head>
14 <% Html.simply_html_head() %>
15 <title>How Luan differs from Lua</title> 11 <title>How Luan differs from Lua</title>
12 <style>
13 @import "/site.css";
14 </style>
16 </head> 15 </head>
17 <body> 16 <body>
18 17
19 <div container>
20 <% Shared.header() %> 18 <% Shared.header() %>
21 <h1>How Luan differs from Lua</h1> 19 <h1>How Luan differs from Lua</h1>
22 20
23 <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> 21 <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>
24 22
25 <hr/> 23 <hr/>
26 24
27 <h2>Contents</h2> 25 <h2>Contents</h2>
28 26
29 <div margin-bottom="1em"><a href="#intro">Introduction</a></div> 27 <div contents><a href="#intro">Introduction</a></div>
30 28
31 <div margin-bottom="1em"> 29 <div contents>
32 <a href="#basic">Basic Concepts</a> 30 <a href="#basic">Basic Concepts</a>
33 <ul> 31 <ul>
34 <li><a href="#types">Values and Types</a></li> 32 <li><a href="#types">Values and Types</a></li>
35 <li><a href="#env">Environments</a></li> 33 <li><a href="#env">Environments</a></li>
36 <li><a href="#error">Error Handling</a></li> 34 <li><a href="#error">Error Handling</a></li>
38 <li><a href="#gc">Garbage Collection</a></li> 36 <li><a href="#gc">Garbage Collection</a></li>
39 <li><a href="#coroutines">Coroutines</a></li> 37 <li><a href="#coroutines">Coroutines</a></li>
40 </ul> 38 </ul>
41 </div> 39 </div>
42 40
43 <div margin-bottom="1em"> 41 <div contents>
44 <a href="#lang">The Language</a> 42 <a href="#lang">The Language</a>
45 <ul> 43 <ul>
46 <li><a href="#lex">Lexical Conventions</a></li> 44 <li><a href="#lex">Lexical Conventions</a></li>
47 <li><a href="#vars">Variables</a></li> 45 <li><a href="#vars">Variables</a></li>
48 <li> 46 <li>
68 </ul> 66 </ul>
69 </div> 67 </div>
70 68
71 <hr/> 69 <hr/>
72 70
73 <h2 <%=heading_options%> ><a name="intro">Introduction</a></h2> 71 <h2 heading><a name="intro">Introduction</a></h2>
74 72
75 <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> 73 <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>
76 74
77 <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p> 75 <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p>
78 76
79 <h2 <%=heading_options%> ><a name="basic">Basic Concepts</a></h2> 77 <h2 heading><a name="basic">Basic Concepts</a></h2>
80 78
81 <h3 <%=heading_options%> ><a name="types">Values and Types</a></h3> 79 <h3 heading><a name="types">Values and Types</a></h3>
82 80
83 <p>Luan does not have the Lua <i>thread</i> type. Luan adds a <i>binary</i> type that Lua doesn't have. This is because Lua strings can represent binary while Luan strings cannot.</p> 81 <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>
84 82
85 <p>The Luan <i>Nil</i> type is implemented as the Java <i>null</i>. The Luan <i>Boolean</i> type is implemented as the Java <i>Boolean</i> type. The Luan <i>Number</i> type is implemented as the Java <i>Number</i> type. The Luan <i>String</i> type is implemented as the Java <i>String</i> type. Actual numbers may be any subclass of the Java <i>Number</i> class.</p> 83 <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>
86 84
87 <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> 85 <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>
88 86
89 <p>The Luan <i>java</i> type is a replacement for Lua's <i>userdata</i>. A Luan <i>java</i> value is nothing more than a Java object that doesn't fall into one of the other recognized types.</p> 87 <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>
90 88
91 <p>The Luan <i>binary</i> type is the Java <i>byte[ ]</i> type which is an array of bytes.</p> 89 <p>The Luan <em>binary</em> type is the Java <em>byte[ ]</em> type which is an array of bytes.</p>
92 90
93 <p>The Luan <i>table</i> type is just like its Lua equivalent, but implemented in Java.</p> 91 <p>The Luan <em>table</em> type is just like its Lua equivalent, but implemented in Java.</p>
94 92
95 <h3 <%=heading_options%> ><a name="env">Environments</a></h3> 93 <h3 heading><a name="env">Environments</a></h3>
96 94
97 <p>Luan has no global environment at all, no <tt>_G</tt>. By default, Luan doesn't define <tt>_ENV</tt> either, but if you define it as a local table in a chunk, then it acts like it does in Lua. When <tt>_ENV</tt> isn't defined, there are no global variables and an unrecognized variable name produces a compile error.</p> 95 <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>
98 96
99 <p>Every module is initialized with two local functions: <tt>require</tt> and <tt>java</tt>. The module then uses these functions to get access to whatever else it needs.</p> 97 <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>
100 98
101 <h3 <%=heading_options%> ><a name="error">Error Handling</a></h3> 99 <h3 heading><a name="error">Error Handling</a></h3>
102 100
103 <p>Luan has the functions <tt>error</tt> and <tt>pcall</tt> but does not have <tt>xpcall</tt>. Luan adds the function <tt>try</tt> 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> 101 <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>
104 102
105 <h3 <%=heading_options%> ><a name="meta">Metatables and Metamethods</a></h3> 103 <h3 heading><a name="meta">Metatables and Metamethods</a></h3>
106 104
107 <p>Luan only has metatable for tables, not for other types.</p> 105 <p>Luan only has metatable for tables, not for other types.</p>
108 106
109 <h3 <%=heading_options%> ><a name="gc">Garbage Collection</a></h3> 107 <h3 heading><a name="gc">Garbage Collection</a></h3>
110 108
111 <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>
112 110
113 <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>
114 112
115 <h3 <%=heading_options%> ><a name="coroutines">Coroutines</a></h3> 113 <h3 heading><a name="coroutines">Coroutines</a></h3>
116 114
117 <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>
118 116
119 <h2 <%=heading_options%> ><a name="lang">The Language</a></h2> 117 <h2 heading><a name="lang">The Language</a></h2>
120 118
121 <h3 <%=heading_options%> ><a name="lex">Lexical Conventions</a></h3> 119 <h3 heading><a name="lex">Lexical Conventions</a></h3>
122 120
123 <p>Unlike Lua, Luan generally considers the end of a line to be the end of a statement. This catches errors and encourages readability. The exception to this is in paranthesis ( <i>(...)</i>, <i>[...]</i>, and <i>{...}</i> ) where the end of line is treated as white space.</p> 121 <p>Unlike Lua, Luan generally considers the end of a line to be the end of a statement. This catches errors and encourages readability. The exception to this is in paranthesis ( <em>(...)</em>, <em>[...]</em>, and <em>{...}</em> ) where the end of line is treated as white space.</p>
124 122
125 <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>
126 124
127 <h3 <%=heading_options%> ><a name="vars">Variables</a></h3> 125 <h3 heading><a name="vars">Variables</a></h3>
128 126
129 <p> 127 <p>
130 By default, there are no global variables and an undefined variable produces a compile error. To enable global variables, one must define <tt>_ENV</tt>. 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.
131 129
132 <h3 <%=heading_options%> ><a name="stmt">Statements</a></h3> 130 <h3 heading><a name="stmt">Statements</a></h3>
133 131
134 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p> 132 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p>
135 133
136 <h4 <%=heading_options%> ><a name="control">Control Structures</a></h4> 134 <h4 heading><a name="control">Control Structures</a></h4>
137 135
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> 136 <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 137
140 <p>Luan does not have a <b>goto</b> statement.</p> 138 <p>Luan does not have a <b>goto</b> statement.</p>
141 139
142 <h4 <%=heading_options%> ><a name="for">For Statement</a></h4> 140 <h4 heading><a name="for">For Statement</a></h4>
143 141
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 <tt>range</tt> function in a generic <b>for</b> statement like this:</p> 142 <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 143
146 <p><tt><pre> 144 <pre>
147 for i in range(from,to,step) do <i>block</i> end 145 for i in range(from,to,step) do <em>block</em> end
148 </pre></tt></p> 146 </pre>
149 147
150 <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 <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>
151 149
152 <p><tt><pre> 150 <pre>
153 for var_1, &middot;&middot;&middot;, var_n in exp do block end 151 for var_1, &middot;&middot;&middot;, var_n in exp do block end
154 </pre></tt></p> 152 </pre>
155 153
156 <p>is equivalent to the code:</p> 154 <p>is equivalent to the code:</p>
157 155
158 <p><tt><pre> 156 <pre>
159 do 157 do
160 local f = exp 158 local f = exp
161 while true do 159 while true do
162 local var_1, &middot;&middot;&middot;, var_n = f() 160 local var_1, &middot;&middot;&middot;, var_n = f()
163 if var_1 == nil then break end 161 if var_1 == nil then break end
164 block 162 block
165 end 163 end
166 end 164 end
167 </pre></tt></p> 165 </pre>
168 166
169 <h4 <%=heading_options%> ><a name="logical">Logical Statements</a></h4> 167 <h4 heading><a name="logical">Logical Statements</a></h4>
170 168
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> 169 <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 170
173 <p><tt><pre> 171 <pre>
174 x==5 or error "x should be 5" 172 x==5 or error "x should be 5"
175 </pre></tt></p> 173 </pre>
176 174
177 <h4 <%=heading_options%> ><a name="template_stmt">Template Statements</a></h4> 175 <h4 heading><a name="template_stmt">Template Statements</a></h4>
178 176
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> 177 <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 178
181 179
182 <h3 <%=heading_options%> ><a name="expr">Expressions</a></h3> 180 <h3 heading><a name="expr">Expressions</a></h3>
183 181
184 <h4 <%=heading_options%> ><a name="conversions">Coercions and Conversions</a></h4> 182 <h4 heading><a name="conversions">Coercions and Conversions</a></h4>
185 183
186 <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p> 184 <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p>
187 185
188 <h4 <%=heading_options%> ><a name="bit">Bitwise Operators</a></h4> 186 <h4 heading><a name="bit">Bitwise Operators</a></h4>
189 187
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> 188 <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 189
192 <h4 <%=heading_options%> ><a name="logical_ops">Logical Operators</a></h4> 190 <h4 heading><a name="logical_ops">Logical Operators</a></h4>
193 191
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> 192 <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 193
196 <h4 <%=heading_options%> ><a name="concatenation">Concatenation</a></h4> 194 <h4 heading><a name="concatenation">Concatenation</a></h4>
197 195
198 <p>Unlike Lua, Luan converts all concatenation operands to strings. 196 <p>Unlike Lua, Luan converts all concatenation operands to strings.
199 197
200 <h4 <%=heading_options%> ><a name="fn_calls">Function Calls</a></h4> 198 <h4 heading><a name="fn_calls">Function Calls</a></h4>
201 199
202 <p>Luan does not support Lua's <tt>v:name(args)</tt> style object-oriented function call. Object oriented programming is done in Luan using closures, so this feature is not needed.</p> 200 <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>
203 201
204 <h4 <%=heading_options%> ><a name="template_expr">Template Expressions</a></h4> 202 <h4 heading><a name="template_expr">Template Expressions</a></h4>
205 203
206 <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> 204 <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>
207
208 </div>
209 205
210 <% Html.simply_html_body_bottom() %>
211 </body> 206 </body>
212 </html> 207 </html>
213 <% 208 <%
214 end 209 end