annotate website/src/diff.html.luan @ 1651:5b8f056527a3

docs work
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 31 Mar 2022 16:13:32 -0600
parents website/src/diff.html@0af6a9d6d12f
children d5779a264a4a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
1 local Luan = require "luan:Luan.luan"
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
2 local error = Luan.error
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
3 local Io = require "luan:Io.luan"
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
4 local Http = require "luan:http/Http.luan"
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
6 local head = Shared.head or error()
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
7 local header = Shared.header or error()
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
8
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
9
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
10 return function()
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
11 Io.stdout = Http.response.text_writer()
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
12 %>
1216
5dbb552075ff doctype
Franklin Schmidt <fschmidt@gmail.com>
parents: 1092
diff changeset
13 <!doctype html>
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
14 <html>
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
15 <head>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
16 <% head() %>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
17 <title>How Luan differs from Lua</title>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
18 </head>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
19 <body>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
20 <% header{[[<a href="docs.html">Documentation</a>]]} %>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
21 <div content>
1324
1660136ac451 website - remove Shared.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1216
diff changeset
22
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
23 <h1><a href="diff.html">How Luan differs from Lua</a></h1>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
25 <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>
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 370
diff changeset
26
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
27 <hr/>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
29 <h2>Contents</h2>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
30
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
31 <div contents><a href="#intro">Introduction</a></div>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
33 <div contents>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
34 <a href="#basic">Basic Concepts</a>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
35 <ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
36 <li><a href="#types">Values and Types</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
37 <li><a href="#env">Environments</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
38 <li><a href="#error">Error Handling</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
39 <li><a href="#meta">Metatables and Metamethods</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
40 <li><a href="#gc">Garbage Collection</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
41 <li><a href="#coroutines">Coroutines</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
42 </ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
43 </div>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
45 <div contents>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
46 <a href="#lang">The Language</a>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
47 <ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
48 <li><a href="#lex">Lexical Conventions</a></li>
512
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
49 <li><a href="#vars">Variables</a></li>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
50 <li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
51 <a href="#stmt">Statements</a>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
52 <ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
53 <li><a href="#control">Control Structures</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
54 <li><a href="#for">For Statement</a></li>
1520
d9a5405a3102 try statement
Franklin Schmidt <fschmidt@gmail.com>
parents: 1384
diff changeset
55 <li><a href="#try">Try Statement</a></li>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
56 <li><a href="#logical">Logical Statements</a></li>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
57 <li><a href="#template_stmt">Template Statements</a></li>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
58 </ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
59 </li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
60 <li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
61 <a href="#expr">Expressions</a>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
62 <ul>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
63 <li><a href="#conversions">Coercions and Conversions</a></li>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
64 <li><a href="#bit">Bitwise Operators</a></li>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
65 <li><a href="#logical_ops">Logical Operators</a></li>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
66 <li><a href="#concatenation">Concatenation</a></li>
686
33f1b4ad2c9d more documentation fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 685
diff changeset
67 <li><a href="#constructors">Table Constructors</a></li>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
68 <li><a href="#fn_calls">Function Calls</a></li>
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
69 </ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
70 </li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
71 </ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
72 </div>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
74 <hr/>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
75
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
76 <h2 heading><a name="intro" href="#intro">Introduction</a></h2>
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 370
diff changeset
77
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
78 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
80 <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
82 <h2 heading><a name="basic" href="#basic">Basic Concepts</a></h2>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
84 <h3 heading><a name="types" href="#types">Values and Types</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
86 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
88 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
90 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
92 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
94 <p>The Luan <em>binary</em> type is the Java <em>byte[ ]</em> type which is an array of bytes.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
96 <p>The Luan <em>table</em> type is just like its Lua equivalent, but implemented in Java.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
98 <h3 heading><a name="env" href="#env">Environments</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
100 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101
1521
d3e61cd2aca0 docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents: 1520
diff changeset
102 <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>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
104 <h3 heading><a name="error" href="#error">Error Handling</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105
1521
d3e61cd2aca0 docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents: 1520
diff changeset
106 <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>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
108 <h3 heading><a name="meta" href="#meta">Metatables and Metamethods</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
110 <p>Luan only has metatable for tables, not for other types.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111
685
1e4b0bc0202d update documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 604
diff changeset
112 <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>
1e4b0bc0202d update documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 604
diff changeset
113
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
114 <h3 heading><a name="gc" href="#gc">Garbage Collection</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
116 <p>Luan uses Java garbage collection. Luan has no special garbage collection methods.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
118 <p>Luan does not yet have weak tables but this will be added.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
120 <h3 heading><a name="coroutines" href="#coroutines">Coroutines</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
122 <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>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
124 <h2 heading><a name="lang" href="#lang">The Language</a></h2>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
126 <h3 heading><a name="lex" href="#lex">Lexical Conventions</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127
685
1e4b0bc0202d update documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 604
diff changeset
128 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
130 <p>Luan has exactly the same set of keywords as Lua and has the same other lexical conventions.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
132 <h3 heading><a name="vars" href="#vars">Variables</a></h3>
512
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
133
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
134 <p>
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
135 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.
512
d96944467ffc update documentation for luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 505
diff changeset
136
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
137 <h3 heading><a name="stmt" href="#stmt">Statements</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138
1521
d3e61cd2aca0 docs and shell bug fix
Franklin Schmidt <fschmidt@gmail.com>
parents: 1520
diff changeset
139 <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
a26fbde7ee28 documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 1090
diff changeset
140
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
141 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
143 <h4 heading><a name="control" href="#control">Control Structures</a></h4>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
145 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146
1645
0af6a9d6d12f minor - keywords
Franklin Schmidt <fschmidt@gmail.com>
parents: 1521
diff changeset
147 <p>Luan adds the <b>continue</b> statement which is used inside loops.</p>
0af6a9d6d12f minor - keywords
Franklin Schmidt <fschmidt@gmail.com>
parents: 1521
diff changeset
148
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
149 <p>Luan does not have a <b>goto</b> statement.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
151 <h4 heading><a name="for" href="#for">For Statement</a></h4>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
153 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
155 <pre>
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
156 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
157 </pre>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
468
9b51e2413cab documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 465
diff changeset
159 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
161 <pre>
390
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
162 for var_1, &middot;&middot;&middot;, var_n in exp do block end
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
163 </pre>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164
389
497d4ef0a89f documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 387
diff changeset
165 <p>is equivalent to the code:</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
167 <pre>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 do
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 local f = exp
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 while true do
390
Franklin Schmidt <fschmidt@gmail.com>
parents: 389
diff changeset
171 local var_1, &middot;&middot;&middot;, var_n = f()
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172 if var_1 == nil then break end
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 block
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 end
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 end
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
176 </pre>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
1520
d9a5405a3102 try statement
Franklin Schmidt <fschmidt@gmail.com>
parents: 1384
diff changeset
178
d9a5405a3102 try statement
Franklin Schmidt <fschmidt@gmail.com>
parents: 1384
diff changeset
179 <h4 heading><a name="try" href="#for">Try Statement</a></h4>
d9a5405a3102 try statement
Franklin Schmidt <fschmidt@gmail.com>
parents: 1384
diff changeset
180
d9a5405a3102 try statement
Franklin Schmidt <fschmidt@gmail.com>
parents: 1384
diff changeset
181 <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>
d9a5405a3102 try statement
Franklin Schmidt <fschmidt@gmail.com>
parents: 1384
diff changeset
182
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
183 <h4 heading><a name="logical" href="#logical">Logical Statements</a></h4>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
185 <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
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
187 <pre>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 x==5 or error "x should be 5"
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
189 </pre>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
191 <h4 heading><a name="template_stmt" href="#template_stmt">Template Statements</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
192
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
193 <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>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
194
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
195
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
196 <h3 heading><a name="expr" href="#expr">Expressions</a></h3>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
197
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
198 <h4 heading><a name="conversions" href="#conversions">Coercions and Conversions</a></h4>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
199
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
200 <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p>
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
201
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
202 <h4 heading><a name="bit" href="#bit">Bitwise Operators</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
203
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
204 <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>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
205
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
206 <h4 heading><a name="logical_ops" href="#logical_ops">Logical Operators</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
207
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
208 <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>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
209
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
210 <h4 heading><a name="concatenation" href="#concatenation">Concatenation</a></h4>
465
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
211
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
212 <p>Unlike Lua, Luan converts all concatenation operands to strings.
47c7de1f2322 documentation work
Franklin Schmidt <fschmidt@gmail.com>
parents: 464
diff changeset
213
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
214 <h4 heading><a name="constructors" href="#constructors">Table Constructors</a></h4>
686
33f1b4ad2c9d more documentation fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 685
diff changeset
215
33f1b4ad2c9d more documentation fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 685
diff changeset
216 <p>Unlike Lua, Luan considers an <b>end_of_line</b> to be a field separator in a table constructor.</p>
33f1b4ad2c9d more documentation fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 685
diff changeset
217
1327
b29eefad2111 website - improve docs
Franklin Schmidt <fschmidt@gmail.com>
parents: 1326
diff changeset
218 <h4 heading><a name="fn_calls" href="#fn_calls">Function Calls</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
219
1090
616761e0b9f6 update documentation for last change
Franklin Schmidt <fschmidt@gmail.com>
parents: 693
diff changeset
220 <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
221
562
7cc9d4a53d3b remove SimplyHTML from documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 513
diff changeset
222 <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
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
223
685
1e4b0bc0202d update documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 604
diff changeset
224 <p>Luan doesn't support <em>proper tail calls</em>. Because Java doesn't support this cleanly, this was left out.</p>
1e4b0bc0202d update documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 604
diff changeset
225
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
226 </div>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
227 </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
228 </html>
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
229 <%
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1645
diff changeset
230 end