Mercurial Hosting > luan
annotate website/src/diff.html @ 370:7999601586b1
minor documentation
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 17 Apr 2015 07:18:39 -0600 |
parents | c207be7cf45d |
children | f08cefa4594c |
rev | line source |
---|---|
353 | 1 <!DOCTYPE html> |
2 <html lang="en"> | |
3 <head> | |
4 <meta charset="utf-8"> | |
5 <meta name="viewport" content="width=device-width, initial-scale=1"> | |
6 | |
370 | 7 <title>How Luan differs from Lua</title> |
353 | 8 |
9 <link href="http://www.simplyhtml.org/assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"> | |
10 <link rel="stylesheet" href="http://www.simplyhtml.org/assets/font-awesome/css/font-awesome.min.css"> | |
11 <script src="http://www.simplyhtml.org/assets/jquery/jquery.min.js"></script> | |
12 | |
13 <link href="http://www.simplyhtml.org/assets/simplyhtml/simplyhtml.css" rel="stylesheet"/> | |
14 <script src="http://www.simplyhtml.org/assets/simplyhtml/simplyhtml.js"></script> | |
15 </head> | |
16 <body> | |
17 <div container> | |
370 | 18 <div><small><a href="/">Luan</a></small></div> |
353 | 19 <h1>How Luan differs from Lua</h1> |
20 | |
370 | 21 <p>This document explains how Luan differs from <a href="http://www.lua.org">Lua</a> as described in the <a href="http://www.lua.org/manual/5.3/">Lua 5.3 Reference Manual</a>.</p> |
353 | 22 |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
23 <h2 margin-top="1em">Contents</h2> |
353 | 24 |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
25 <div margin-bottom="1em"><a href="#intro">Introduction</a></div> |
353 | 26 |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
27 <div margin-bottom="1em"> |
353 | 28 <a href="#basic">Basic Concepts</a> |
29 <ul> | |
30 <li><a href="#types">Values and Types</a></li> | |
31 <li><a href="#env">Environments</a></li> | |
32 <li><a href="#error">Error Handling</a></li> | |
33 <li><a href="#meta">Metatables and Metamethods</a></li> | |
34 <li><a href="#gc">Garbage Collection</a></li> | |
35 <li><a href="#coroutines">Coroutines</a></li> | |
36 </ul> | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
37 </div> |
353 | 38 |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
39 <div margin-bottom="1em"> |
353 | 40 <a href="#lang">The Language</a> |
41 <ul> | |
42 <li><a href="#lex">Lexical Conventions</a></li> | |
43 <li> | |
44 <a href="#stmt">Statements</a> | |
45 <ul> | |
46 <li><a href="#control">Control Structures</a></li> | |
47 <li><a href="#for">For Statement</a></li> | |
48 <li><a href="#logical">Logical Statements</a></li> | |
367 | 49 <li><a href="#template-stmt">Template Statements</a></li> |
50 </ul> | |
51 </li> | |
52 <li> | |
53 <a href="#expr">Expressions</a> | |
54 <ul> | |
55 <li><a href="#bit">Bitwise Operators</a></li> | |
56 <li><a href="#local-ops">Logical Operators</a></li> | |
57 <li><a href="#fn-call">Function Calls</a></li> | |
58 <li><a href="#template-expr">Template Expressions</a></li> | |
353 | 59 </ul> |
60 </li> | |
61 </ul> | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
62 </div> |
353 | 63 |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
64 <h2 margin-top="1em"><a name="intro">Introduction</a></h2> |
353 | 65 |
66 <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> | |
67 | |
68 <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p> | |
69 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
70 <h2 margin-top="1em"><a name="basic">Basic Concepts</a></h2> |
353 | 71 |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
72 <h3 margin-top="1em"><a name="types">Values and Types</a></h3> |
353 | 73 |
74 <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> | |
75 | |
76 <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> | |
77 | |
78 <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> | |
79 | |
80 <p>Luan <i>userdata</i> is nothing more than a Java object that doesn't fall into one of the other recognized types.</p> | |
81 | |
82 <p>The Luan <i>binary</i> type is the Java <i>byte[ ]</i> type which is an array of bytes.</p> | |
83 | |
84 <p>The Luan <i>table</i> type is just like its Lua equivalent, but implemented in Java.</p> | |
85 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
86 <h3 margin-top="1em"><a name="env">Environments</a></h3> |
353 | 87 |
88 <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> | |
89 | |
90 <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> | |
91 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
92 <h3 margin-top="1em"><a name="error">Error Handling</a></h3> |
353 | 93 |
94 <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> | |
95 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
96 <h3 margin-top="1em"><a name="meta">Metatables and Metamethods</a></h3> |
353 | 97 |
98 <p>to document later...</p> | |
99 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
100 <h3 margin-top="1em"><a name="gc">Garbage Collection</a></h3> |
353 | 101 |
102 <p>Luan uses Java garbage collection. Luan has no special garbage collection methods.</p> | |
103 | |
104 <p>Luan does not yet have weak tables but this will be added.</p> | |
105 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
106 <h3 margin-top="1em"><a name="coroutines">Coroutines</a></h3> |
353 | 107 |
108 <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> | |
109 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
110 <h2 margin-top="1em"><a name="lang">The Language</a></h2> |
353 | 111 |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
112 <h3 margin-top="1em"><a name="lex">Lexical Conventions</a></h3> |
353 | 113 |
114 <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> | |
115 | |
116 <p>Luan has exactly the same set of keywords as Lua and has the same other lexical conventions.</p> | |
117 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
118 <h3 margin-top="1em"><a name="stmt">Statements</a></h3> |
353 | 119 |
120 <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p> | |
121 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
122 <h4 margin-top="1em"><a name="control">Control Structures</a></h4> |
353 | 123 |
124 <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> | |
125 | |
126 <p>Luan does not have a <b>goto</b> statement.</p> | |
127 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
128 <h4 margin-top="1em"><a name="for">For Statement</a></h4> |
353 | 129 |
130 <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> | |
131 | |
132 <tt><pre> | |
133 for i in range(from,to,step) do <i>block</i> end | |
134 </pre></tt> | |
135 | |
136 <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> | |
137 | |
138 <tt><pre> | |
139 for var_1, ···, var_n in exp do block end | |
140 </pre></tt> | |
141 | |
142 <p>is equivalent to the code:</p> | |
143 | |
144 <tt><pre> | |
145 do | |
146 local f = exp | |
147 while true do | |
148 local var_1, ···, var_n = f() | |
149 if var_1 == nil then break end | |
150 block | |
151 end | |
152 end | |
153 </pre></tt> | |
154 | |
354
705e4d6c3dbb
improve formatting of diff.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
353
diff
changeset
|
155 <h4 margin-top="1em"><a name="logical">Logical Statements</a></h4> |
353 | 156 |
157 <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> | |
158 | |
159 <tt><pre> | |
160 x==5 or error "x should be 5" | |
161 </pre></tt> | |
162 | |
367 | 163 <h4 margin-top="1em"><a name="template-stmt">Template Statements</a></h4> |
164 | |
165 <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> | |
166 | |
167 <tt><pre> | |
168 local name = "Bob" | |
169 %> | |
170 Hello <%=name%>! | |
171 Bye <%=name%>. | |
172 <% | |
173 </pre></tt> | |
174 | |
175 <p>is equivalent to the code:</p> | |
176 | |
177 <tt><pre> | |
178 local name = "Bob" | |
370 | 179 require("luan:Io").stdout.write( %> |
367 | 180 Hello <%=name%>! |
181 Bye <%=name%>. | |
182 <% ) | |
183 </pre></tt> | |
184 | |
185 <h3 margin-top="1em"><a name="expr">Expressions</a></h3> | |
186 | |
187 <h4 margin-top="1em"><a name="bit">Bitwise Operators</a></h4> | |
188 | |
189 <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> | |
190 | |
191 <h4 margin-top="1em"><a name="local-ops">Logical Operators</a></h4> | |
192 | |
193 <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> | |
194 | |
195 <h4 margin-top="1em"><a name="fn-call">Function Calls</a></h4> | |
196 | |
197 <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> | |
198 | |
199 <h4 margin-top="1em"><a name="template-expr">Template Expressions</a></h4> | |
200 | |
201 <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> | |
202 | |
203 <tt><pre> | |
204 local name = "Bob" | |
205 write( %>Hello <%=name%>!<% ) | |
206 </pre></tt> | |
207 | |
370 | 208 <p>This is equivalent to the code:</p> |
209 | |
210 <tt><pre> | |
211 local name = "Bob" | |
212 write( "Hello ", name, "!" ) | |
213 </pre></tt> | |
214 | |
215 <p>The strings in template expressions may be multiple lines.</p> | |
367 | 216 |
353 | 217 </div> |
218 | |
219 <script src="http://www.simplyhtml.org/assets/bootstrap/js/bootstrap.min.js"></script> | |
220 </body> | |
221 </html> |