annotate website/src/diff.html.luan @ 386:db23f654f87d

make all of website use luan
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 23 Apr 2015 18:09:12 -0600
parents website/src/diff.html@f08cefa4594c
children 23d075ce1e48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
1 local Io = require "luan:Io"
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
2 local Html = require "luan:Html"
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
3 local Http = require "luan:web/Http"
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
6 function service()
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
7 Io.stdout = Http.response.text_writer()
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
8 Html.simply_html_page{
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
9 head = function() %>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
10 <title>How Luan differs from Lua</title>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
11 <% end;
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
12 body = function() %>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
14 <div container>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
15 <div><small><a href="/">Luan</a></small></div>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
16 <h1>How Luan differs from Lua</h1>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
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>
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 370
diff changeset
19
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
20 <hr/>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
22 <h2>Contents</h2>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
23
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
24 <div margin-bottom="1em"><a href="#intro">Introduction</a></div>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
26 <div margin-bottom="1em">
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
27 <a href="#basic">Basic Concepts</a>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
28 <ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
29 <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
30 <li><a href="#env">Environments</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
31 <li><a href="#error">Error Handling</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
32 <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
33 <li><a href="#gc">Garbage Collection</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
34 <li><a href="#coroutines">Coroutines</a></li>
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 </div>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
38 <div margin-bottom="1em">
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
39 <a href="#lang">The Language</a>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
40 <ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
41 <li><a href="#lex">Lexical Conventions</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
42 <li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
43 <a href="#stmt">Statements</a>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
44 <ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
45 <li><a href="#control">Control Structures</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
46 <li><a href="#for">For Statement</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
47 <li><a href="#logical">Logical Statements</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
48 <li><a href="#template-stmt">Template Statements</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
49 </ul>
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 <li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
52 <a href="#expr">Expressions</a>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
53 <ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
54 <li><a href="#bit">Bitwise Operators</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
55 <li><a href="#local-ops">Logical Operators</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
56 <li><a href="#fn-call">Function Calls</a></li>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
57 <li><a href="#template-expr">Template Expressions</a></li>
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 </ul>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
61 </div>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
63 <hr/>
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
64
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
65 <h2 margin-top="1em"><a name="intro">Introduction</a></h2>
372
f08cefa4594c start editing manual
Franklin Schmidt <fschmidt@gmail.com>
parents: 370
diff changeset
66
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
67 <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
68
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
69 <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
70
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
71 <h2 margin-top="1em"><a name="basic">Basic Concepts</a></h2>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
73 <h3 margin-top="1em"><a name="types">Values and Types</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
75 <p>Luan does not have the Lua <i>thread</i> type. Luan add a <i>binary</i> 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
76
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
77 <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>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
79 <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
80
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
81 <p>Luan <i>userdata</i> 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
82
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
83 <p>The Luan <i>binary</i> type is the Java <i>byte[ ]</i> type which is an array of bytes.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
85 <p>The Luan <i>table</i> type is just like its Lua equivalent, but implemented in Java.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
87 <h3 margin-top="1em"><a name="env">Environments</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
89 <p>Luan has an <tt>_ENV</tt> which is like its Lua equivalent. However Luan has no global environment at all, no <tt>_G</tt>.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
91 <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>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
93 <h3 margin-top="1em"><a name="error">Error Handling</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
95 <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.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
97 <h3 margin-top="1em"><a name="meta">Metatables and Metamethods</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
99 <p>to document later...</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
101 <h3 margin-top="1em"><a name="gc">Garbage Collection</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
103 <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
104
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
105 <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
106
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
107 <h3 margin-top="1em"><a name="coroutines">Coroutines</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
109 <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
110
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
111 <h2 margin-top="1em"><a name="lang">The Language</a></h2>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
113 <h3 margin-top="1em"><a name="lex">Lexical Conventions</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
115 <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>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
117 <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
118
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
119 <h3 margin-top="1em"><a name="stmt">Statements</a></h3>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
123 <h4 margin-top="1em"><a name="control">Control Structures</a></h4>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
125 <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
126
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
127 <p>Luan does not have a <b>goto</b> statement.</p>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
129 <h4 margin-top="1em"><a name="for">For Statement</a></h4>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
131 <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>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
133 <tt><pre>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 for i in range(from,to,step) do <i>block</i> end
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 </pre></tt>
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 <p>The Luan generic <b>for</b> statement is simpler than the Lua version because Luan only uses and expression, not an explist. So a <b>for</b> statement like:</p>
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 <tt><pre>
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 for var_1, ยทยทยท, var_n in exp do block end
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 </pre></tt>
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 <p>is equivalent to the code:</p>
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 <tt><pre>
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 do
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 local f = exp
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 while true do
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 local var_1, ยทยทยท, var_n = f()
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 if var_1 == nil then break end
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 block
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 end
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 end
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
154 </pre></tt>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
156 <h4 margin-top="1em"><a name="logical">Logical Statements</a></h4>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
158 <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
159
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
160 <tt><pre>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 x==5 or error "x should be 5"
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
162 </pre></tt>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
164 <h4 margin-top="1em"><a name="template-stmt">Template Statements</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
165
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
166 <p>Template statements are based on <a href="#template-expr">template exressions</a> and provide the full equivalent of <a href="http://en.wikipedia.org/wiki/JavaServer_Pages">JSP</a> but in a general way. Template statements write the equivalent template exression to standard output. For example:</p>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
167
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
168 <tt><pre><%=Html.encode[[
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
169 local name = "Bob"
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
170 %>
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
171 Hello <%=name%>!
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
172 Bye <%=name%>.
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
173 <%
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
174 ]]%></pre></tt>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
175
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
176 <p>is equivalent to the code:</p>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
177
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
178 <tt><pre><%=Html.encode[[
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
179 local name = "Bob"
370
7999601586b1 minor documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 367
diff changeset
180 require("luan:Io").stdout.write( %>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
181 Hello <%=name%>!
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
182 Bye <%=name%>.
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
183 <% )
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
184 ]]%></pre></tt>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
185
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
186 <h3 margin-top="1em"><a name="expr">Expressions</a></h3>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
187
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
188 <h4 margin-top="1em"><a name="bit">Bitwise Operators</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
189
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
190 <p>Bitwise operators appear to be 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
191
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
192 <h4 margin-top="1em"><a name="local-ops">Logical Operators</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
193
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
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>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
195
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
196 <h4 margin-top="1em"><a name="fn-call">Function Calls</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
197
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
198 <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>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
199
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
200 <h4 margin-top="1em"><a name="template-expr">Template Expressions</a></h4>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
201
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
202 <p>Luan adds a new type of expression based on <a href="http://en.wikipedia.org/wiki/JavaServer_Pages">JSP</a> called template expressions. Template expressions return multiple values. Here is an example:</p>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
203
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
204 <tt><pre><%=Html.encode[[
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
205 local name = "Bob"
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
206 write( %>Hello <%=name%>!<% )
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
207 ]]%></pre></tt>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
208
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
209 <p>This is equivalent to the code:</p>
370
7999601586b1 minor documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 367
diff changeset
210
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
211 <tt><pre>
370
7999601586b1 minor documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 367
diff changeset
212 local name = "Bob"
7999601586b1 minor documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 367
diff changeset
213 write( "Hello ", name, "!" )
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
214 </pre></tt>
370
7999601586b1 minor documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 367
diff changeset
215
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
216 <p>The strings in template expressions may be multiple lines.</p>
367
c207be7cf45d more documentation
Franklin Schmidt <fschmidt@gmail.com>
parents: 354
diff changeset
217
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
218 </div>
353
38c19ecc384d start documentation
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
219
386
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
220 <% end;
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
221 }
db23f654f87d make all of website use luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 372
diff changeset
222 end