Mercurial Hosting > luan
annotate website/src/diff.html.luan @ 1797:ba43135bb98d
backticks docs
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 11 Feb 2024 18:52:53 -0700 |
parents | 2968e43cdd44 |
children | f44dcb3fedf7 |
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 %> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
30 <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> |
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> |
1653 | 41 <% |
42 end | |
43 } | |
44 env = { | |
45 title = "Environments" | |
46 content = function() | |
47 %> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
48 <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 | 49 |
1521
d3e61cd2aca0
docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents:
1520
diff
changeset
|
50 <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 | 51 <% |
52 end | |
53 } | |
54 error = { | |
55 title = "Error Handling" | |
56 content = function() | |
57 %> | |
1521
d3e61cd2aca0
docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents:
1520
diff
changeset
|
58 <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 | 59 <% |
60 end | |
61 } | |
62 meta = { | |
63 title = "Metatables and Metamethods" | |
64 content = function() | |
65 %> | |
465 | 66 <p>Luan only has metatable for tables, not for other types.</p> |
353 | 67 |
685 | 68 <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 | 69 <% |
70 end | |
71 } | |
72 gc = { | |
73 title = "Garbage Collection" | |
74 content = function() | |
75 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
76 <p>Luan uses Java garbage collection. Luan has no special garbage collection methods.</p> |
353 | 77 |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
78 <p>Luan does not yet have weak tables but this will be added.</p> |
1653 | 79 <% |
80 end | |
81 } | |
82 coroutines = { | |
83 title = "Coroutines" | |
84 content = function() | |
85 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
86 <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 | 87 <% |
88 end | |
89 } | |
90 } | |
91 } | |
92 lang = { | |
93 title = "The Language" | |
94 subs = { | |
95 lex = { | |
96 title = "Lexical Conventions" | |
97 content = function() | |
98 %> | |
685 | 99 <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 | 100 |
1660 | 101 <p>Luan has a similar set of keywords to Lua and has the same other lexical conventions.</p> |
1653 | 102 <% |
103 end | |
104 } | |
105 vars = { | |
106 title = "Variables" | |
107 content = function() | |
108 %> | |
109 <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> | |
110 <% | |
111 end | |
112 } | |
113 stmt = { | |
114 title = "Statements" | |
115 content = function() | |
116 %> | |
1521
d3e61cd2aca0
docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents:
1520
diff
changeset
|
117 <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 | 118 |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
119 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p> |
1653 | 120 <% |
121 end | |
122 subs = { | |
123 control = { | |
124 title = "Control Structures" | |
125 content = function() | |
126 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
127 <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 | 128 |
1645 | 129 <p>Luan adds the <b>continue</b> statement which is used inside loops.</p> |
130 | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
131 <p>Luan does not have a <b>goto</b> statement.</p> |
1653 | 132 <% |
133 end | |
134 } | |
135 ["for"] = { | |
136 title = "For Statement" | |
137 content = function() | |
138 %> | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
139 <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 | 140 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
141 <pre> |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
142 for i in range(from,to,step) do <em>block</em> end |
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
143 </pre> |
353 | 144 |
468 | 145 <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 | 146 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
147 <pre> |
390 | 148 for var_1, ···, var_n in exp do block end |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
149 </pre> |
353 | 150 |
389 | 151 <p>is equivalent to the code:</p> |
353 | 152 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
153 <pre> |
353 | 154 do |
155 local f = exp | |
156 while true do | |
390 | 157 local var_1, ···, var_n = f() |
353 | 158 if var_1 == nil then break end |
159 block | |
160 end | |
161 end | |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
162 </pre> |
1653 | 163 <% |
164 end | |
165 } | |
166 ["try"] = { | |
167 title = "Try Statement" | |
168 content = function() | |
169 %> | |
1520 | 170 <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 | 171 <% |
172 end | |
173 } | |
174 logical = { | |
175 title = "Logical Statements" | |
176 content = function() | |
177 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
178 <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 | 179 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
180 <pre> |
353 | 181 x==5 or error "x should be 5" |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
182 </pre> |
1653 | 183 <% |
184 end | |
185 } | |
186 template_stmt = { | |
187 title = "Template Statements" | |
188 content = function() | |
189 %> | |
465 | 190 <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 | 191 <% |
192 end | |
193 } | |
194 } | |
195 } | |
196 expr = { | |
197 title = "Expressions" | |
198 subs = { | |
199 conversions = { | |
200 title = "Coercions and Conversions" | |
201 content = function() | |
202 %> | |
465 | 203 <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p> |
1653 | 204 <% |
205 end | |
206 } | |
207 bit = { | |
208 title = "Bitwise Operators" | |
209 content = function() | |
210 %> | |
465 | 211 <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 | 212 <% |
213 end | |
214 } | |
215 logical_ops = { | |
216 title = "Logical Operators" | |
217 content = function() | |
218 %> | |
386
db23f654f87d
make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
372
diff
changeset
|
219 <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 | 220 <% |
221 end | |
222 } | |
223 concatenation = { | |
224 title = "Concatenation" | |
225 content = function() | |
226 %> | |
227 <p>Unlike Lua, Luan converts all concatenation operands to strings.</p> | |
228 <% | |
229 end | |
230 } | |
231 constructors = { | |
232 title = "Table Constructors" | |
233 content = function() | |
234 %> | |
686
33f1b4ad2c9d
more documentation fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
685
diff
changeset
|
235 <p>Unlike Lua, Luan considers an <b>end_of_line</b> to be a field separator in a table constructor.</p> |
1653 | 236 <% |
237 end | |
238 } | |
239 fn_calls = { | |
240 title = "Function Calls" | |
241 content = function() | |
242 %> | |
1090
616761e0b9f6
update documentation for last change
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
243 <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
|
244 |
562
7cc9d4a53d3b
remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
513
diff
changeset
|
245 <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 | 246 |
685 | 247 <p>Luan doesn't support <em>proper tail calls</em>. Because Java doesn't support this cleanly, this was left out.</p> |
1653 | 248 <% |
249 end | |
250 } | |
1797 | 251 backticks = { |
252 title = "Backticks" | |
253 content = function() | |
254 %> | |
255 <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> | |
256 <% | |
257 end | |
258 } | |
1653 | 259 } |
260 } | |
261 } | |
262 } | |
263 } | |
685 | 264 |
1653 | 265 |
266 return function() | |
267 Io.stdout = Http.response.text_writer() | |
268 %> | |
269 <!doctype html> | |
270 <html> | |
271 <head> | |
272 <% head() %> | |
273 <title>How Luan differs from Lua</title> | |
274 </head> | |
275 <body> | |
276 <% docs_header() %> | |
277 <div content> | |
278 <h1><a href="diff.html">How Luan differs from Lua</a></h1> | |
279 <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> | |
280 <hr> | |
281 <h2>Contents</h2> | |
282 <div toc> | |
283 <% show_toc(content) %> | |
284 </div> | |
285 <hr> | |
286 <% show_content(content,2) %> | |
1651 | 287 </div> |
288 </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
|
289 </html> |
1651 | 290 <% |
291 end |