Mercurial Hosting > luan
annotate website/src/diff.html.luan @ 1831:8f9ae295bf6a default tip
add Hosted.authorize
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 26 Sep 2024 15:07:45 -0600 |
parents | 50e570b598b2 |
children |
rev | line source |
---|---|
1651 | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | |
3 local Io = require "luan:Io.luan" | |
4 local Http = require "luan:http/Http.luan" | |
5 local Shared = require "site:/lib/Shared.luan" | |
6 local head = Shared.head or error() | |
1652 | 7 local docs_header = Shared.docs_header or error() |
1653 | 8 local show_toc = Shared.show_toc or error() |
9 local show_content = Shared.show_content or error() | |
1651 | 10 |
11 | |
1653 | 12 local content = { |
13 intro = { | |
14 title = "Introduction" | |
15 content = function() | |
1651 | 16 %> |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
17 <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> |
353 | 18 |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
19 <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p> |
1653 | 20 <% |
21 end | |
22 } | |
23 basic = { | |
24 title = "Basic Concepts" | |
25 subs = { | |
26 types = { | |
27 title = "Values and Types" | |
28 content = function() | |
29 %> | |
1813 | 30 <p>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> |
353 | 31 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
32 <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> |
353 | 33 |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
34 <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> |
353 | 35 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
36 <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> |
353 | 37 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
38 <p>The Luan <em>binary</em> type is the Java <em>byte[ ]</em> type which is an array of bytes.</p> |
353 | 39 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
40 <p>The Luan <em>table</em> type is just like its Lua equivalent, but implemented in Java.</p> |
1813 | 41 |
1814 | 42 <p>Luan does not have the Lua <em>thread</em> type which aren't actually threads but in fact are coroutines. Luan has real threads. This is particularly valuable for web serving where each request is handled by a thread. But thread synchronization is too complicated for application programmers. So Luan makes mutable objects immutable when they become accessible by multiple threads. This eliminates the need for thread synchronization. If there is a need to share mutable state across threads, there are special functions for this.</p> |
1653 | 43 <% |
44 end | |
45 } | |
46 env = { | |
47 title = "Environments" | |
48 content = function() | |
49 %> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
50 <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> |
353 | 51 |
1521
d3e61cd2aca0
docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents:
1520
diff
changeset
|
52 <p>Every module is initialized with one local function: <code>require</code>. The module then uses this function to get access to whatever else it needs.</p> |
1653 | 53 <% |
54 end | |
55 } | |
56 error = { | |
57 title = "Error Handling" | |
58 content = function() | |
59 %> | |
1521
d3e61cd2aca0
docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents:
1520
diff
changeset
|
60 <p>Luan has the function <code>error</code> but does not have <code>pcall</code> or <code>xpcall</code>. Luan adds the <a href="#try">try statement</a> instead. Luan errors are implemented as an error table, not as a message object.</p> |
1653 | 61 <% |
62 end | |
63 } | |
64 meta = { | |
65 title = "Metatables and Metamethods" | |
66 content = function() | |
67 %> | |
465 | 68 <p>Luan only has metatable for tables, not for other types.</p> |
353 | 69 |
685 | 70 <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> |
1653 | 71 <% |
72 end | |
73 } | |
74 gc = { | |
75 title = "Garbage Collection" | |
76 content = function() | |
77 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
78 <p>Luan uses Java garbage collection. Luan has no special garbage collection methods.</p> |
353 | 79 |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
80 <p>Luan does not yet have weak tables but this will be added.</p> |
1653 | 81 <% |
82 end | |
83 } | |
84 coroutines = { | |
85 title = "Coroutines" | |
86 content = function() | |
87 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
88 <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> |
1653 | 89 <% |
90 end | |
91 } | |
92 } | |
93 } | |
94 lang = { | |
95 title = "The Language" | |
96 subs = { | |
97 lex = { | |
98 title = "Lexical Conventions" | |
99 content = function() | |
100 %> | |
685 | 101 <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> |
353 | 102 |
1660 | 103 <p>Luan has a similar set of keywords to Lua and has the same other lexical conventions.</p> |
1653 | 104 <% |
105 end | |
106 } | |
107 vars = { | |
108 title = "Variables" | |
109 content = function() | |
110 %> | |
111 <p>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.</p> | |
112 <% | |
113 end | |
114 } | |
115 stmt = { | |
116 title = "Statements" | |
117 content = function() | |
118 %> | |
1521
d3e61cd2aca0
docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents:
1520
diff
changeset
|
119 <p>Luan adds the block terminators <b>end_do</b>, <b>end_for</b>, <b>end_function</b>, <b>end_if</b>, <b>end_try</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> |
1092 | 120 |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
121 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p> |
1653 | 122 <% |
123 end | |
124 subs = { | |
125 control = { | |
126 title = "Control Structures" | |
127 content = function() | |
128 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
129 <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> |
353 | 130 |
1645 | 131 <p>Luan adds the <b>continue</b> statement which is used inside loops.</p> |
132 | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
133 <p>Luan does not have a <b>goto</b> statement.</p> |
1653 | 134 <% |
135 end | |
136 } | |
137 ["for"] = { | |
138 title = "For Statement" | |
139 content = function() | |
140 %> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
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> |
353 | 142 |
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
143 <code block> |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
144 for i in range(from,to,step) do <em>block</em> end |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
145 </code> |
353 | 146 |
468 | 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> |
353 | 148 |
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
149 <code block> |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
150 for var_1, ···, var_n in exp do block end |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
151 </code> |
353 | 152 |
389 | 153 <p>is equivalent to the code:</p> |
353 | 154 |
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
155 <code block> |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
156 do |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
157 local f = exp |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
158 while true do |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
159 local var_1, ···, var_n = f() |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
160 if var_1 == nil then break end |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
161 block |
353 | 162 end |
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
163 end |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
164 </code> |
1653 | 165 <% |
166 end | |
167 } | |
168 ["try"] = { | |
169 title = "Try Statement" | |
170 content = function() | |
171 %> | |
1520 | 172 <p>Unlike Lua, Luan has a <b>try</b> statement. See <a href="manual.html#try">Try Statement</a> in the Luan Reference Manual. This also eliminates the need for Lua's <b>pcall</b> function which Luan doesn't have.</p> |
1653 | 173 <% |
174 end | |
175 } | |
176 logical = { | |
177 title = "Logical Statements" | |
178 content = function() | |
179 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
180 <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> |
353 | 181 |
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
182 <code block> |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
183 x==5 or error "x should be 5" |
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1797
diff
changeset
|
184 </code> |
1653 | 185 <% |
186 end | |
187 } | |
188 template_stmt = { | |
189 title = "Template Statements" | |
190 content = function() | |
191 %> | |
465 | 192 <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> |
1653 | 193 <% |
194 end | |
195 } | |
196 } | |
197 } | |
198 expr = { | |
199 title = "Expressions" | |
200 subs = { | |
201 conversions = { | |
202 title = "Coercions and Conversions" | |
203 content = function() | |
204 %> | |
465 | 205 <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p> |
1653 | 206 <% |
207 end | |
208 } | |
209 bit = { | |
210 title = "Bitwise Operators" | |
211 content = function() | |
212 %> | |
465 | 213 <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> |
1653 | 214 <% |
215 end | |
216 } | |
217 logical_ops = { | |
218 title = "Logical Operators" | |
219 content = function() | |
220 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
221 <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> |
1653 | 222 <% |
223 end | |
224 } | |
225 concatenation = { | |
226 title = "Concatenation" | |
227 content = function() | |
228 %> | |
229 <p>Unlike Lua, Luan converts all concatenation operands to strings.</p> | |
230 <% | |
231 end | |
232 } | |
233 constructors = { | |
234 title = "Table Constructors" | |
235 content = function() | |
236 %> | |
686
33f1b4ad2c9d
more documentation fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
685
diff
changeset
|
237 <p>Unlike Lua, Luan considers an <b>end_of_line</b> to be a field separator in a table constructor.</p> |
1653 | 238 <% |
239 end | |
240 } | |
241 fn_calls = { | |
242 title = "Function Calls" | |
243 content = function() | |
244 %> | |
1090
616761e0b9f6
update documentation for last change
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
245 <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> |
616761e0b9f6
update documentation for last change
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
246 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
247 <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> |
367 | 248 |
685 | 249 <p>Luan doesn't support <em>proper tail calls</em>. Because Java doesn't support this cleanly, this was left out.</p> |
1653 | 250 <% |
251 end | |
252 } | |
1797 | 253 backticks = { |
254 title = "Backticks" | |
255 content = function() | |
256 %> | |
257 <p>Backtick expressions are a Luan addition that don't exist in Lua. See <a href="manual.html#backticks">Backticks</a> in the Luan Reference Manual.</p> | |
258 <% | |
259 end | |
260 } | |
1653 | 261 } |
262 } | |
263 } | |
264 } | |
265 } | |
685 | 266 |
1653 | 267 |
268 return function() | |
269 Io.stdout = Http.response.text_writer() | |
270 %> | |
271 <!doctype html> | |
272 <html> | |
273 <head> | |
274 <% head() %> | |
275 <title>How Luan differs from Lua</title> | |
276 </head> | |
277 <body> | |
278 <% docs_header() %> | |
279 <div content> | |
280 <h1><a href="diff.html">How Luan differs from Lua</a></h1> | |
1827 | 281 <p>This document explains how Luan differs from <a href="https://www.lua.org/">Lua</a> as described in the <a href="https://www.lua.org/manual/5.3/">Lua 5.3 Reference Manual</a>.</p> |
1653 | 282 <hr> |
283 <h2>Contents</h2> | |
284 <div toc> | |
285 <% show_toc(content) %> | |
286 </div> | |
287 <hr> | |
288 <% show_content(content,2) %> | |
1651 | 289 </div> |
290 </body> | |
391
2f5cc9c2cbf0
replace Html.simply_html_page with simply_html_head and simply_html_body_bottom
Franklin Schmidt <fschmidt@gmail.com>
parents:
390
diff
changeset
|
291 </html> |
1651 | 292 <% |
293 end |