Mercurial Hosting > luan
comparison website/src/diff.html.luan @ 389:497d4ef0a89f
documentation work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 24 Apr 2015 12:25:50 -0600 |
parents | 23d075ce1e48 |
children | bfbbce690bba |
comparison
equal
deleted
inserted
replaced
388:12ee9a336b95 | 389:497d4ef0a89f |
---|---|
129 | 129 |
130 <h4 margin-top="1em"><a name="for">For Statement</a></h4> | 130 <h4 margin-top="1em"><a name="for">For Statement</a></h4> |
131 | 131 |
132 <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> | 132 <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> |
133 | 133 |
134 <tt><pre> | 134 <p><tt><pre> |
135 for i in range(from,to,step) do <i>block</i> end | 135 for i in range(from,to,step) do <i>block</i> end |
136 </pre></tt> | 136 </pre></tt></p> |
137 | 137 |
138 <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> | 138 <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> |
139 | 139 |
140 <tt><pre> | 140 <p><tt><pre> |
141 for var_1, ···, var_n in exp do block end | 141 for var_1, ···, var_n in exp do block end |
142 </pre></tt> | 142 </pre></tt></p> |
143 | 143 |
144 <p>is equivalent to the code:</p> | 144 <p>is equivalent to the code:</p> |
145 | 145 |
146 <tt><pre> | 146 <p><tt><pre> |
147 do | 147 do |
148 local f = exp | 148 local f = exp |
149 while true do | 149 while true do |
150 local var_1, ···, var_n = f() | 150 local var_1, ···, var_n = f() |
151 if var_1 == nil then break end | 151 if var_1 == nil then break end |
152 block | 152 block |
153 end | 153 end |
154 end | 154 end |
155 </pre></tt> | 155 </pre></tt></p> |
156 | 156 |
157 <h4 margin-top="1em"><a name="logical">Logical Statements</a></h4> | 157 <h4 margin-top="1em"><a name="logical">Logical Statements</a></h4> |
158 | 158 |
159 <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> | 159 <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> |
160 | 160 |
161 <tt><pre> | 161 <p><tt><pre> |
162 x==5 or error "x should be 5" | 162 x==5 or error "x should be 5" |
163 </pre></tt> | 163 </pre></tt></p> |
164 | 164 |
165 <h4 margin-top="1em"><a name="template-stmt">Template Statements</a></h4> | 165 <h4 margin-top="1em"><a name="template-stmt">Template Statements</a></h4> |
166 | 166 |
167 <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> | 167 <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> |
168 | 168 |
169 <tt><pre><%=Html.encode[[ | 169 <p><tt><pre><%=Html.encode[[ |
170 local name = "Bob" | 170 local name = "Bob" |
171 %> | 171 %> |
172 Hello <%=name%>! | 172 Hello <%=name%>! |
173 Bye <%=name%>. | 173 Bye <%=name%>. |
174 <% | 174 <% |
175 ]]%></pre></tt> | 175 ]]%></pre></tt></p> |
176 | 176 |
177 <p>is equivalent to the code:</p> | 177 <p>is equivalent to the code:</p> |
178 | 178 |
179 <tt><pre><%=Html.encode[[ | 179 <p><tt><pre><%=Html.encode[[ |
180 local name = "Bob" | 180 local name = "Bob" |
181 require("luan:Io").stdout.write( %> | 181 require("luan:Io").stdout.write( %> |
182 Hello <%=name%>! | 182 Hello <%=name%>! |
183 Bye <%=name%>. | 183 Bye <%=name%>. |
184 <% ) | 184 <% ) |
185 ]]%></pre></tt> | 185 ]]%></pre></tt></p> |
186 | 186 |
187 <h3 margin-top="1em"><a name="expr">Expressions</a></h3> | 187 <h3 margin-top="1em"><a name="expr">Expressions</a></h3> |
188 | 188 |
189 <h4 margin-top="1em"><a name="bit">Bitwise Operators</a></h4> | 189 <h4 margin-top="1em"><a name="bit">Bitwise Operators</a></h4> |
190 | 190 |
200 | 200 |
201 <h4 margin-top="1em"><a name="template-expr">Template Expressions</a></h4> | 201 <h4 margin-top="1em"><a name="template-expr">Template Expressions</a></h4> |
202 | 202 |
203 <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> | 203 <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> |
204 | 204 |
205 <tt><pre><%=Html.encode[[ | 205 <p><tt><pre><%=Html.encode[[ |
206 local name = "Bob" | 206 local name = "Bob" |
207 write( %>Hello <%=name%>!<% ) | 207 write( %>Hello <%=name%>!<% ) |
208 ]]%></pre></tt> | 208 ]]%></pre></tt></p> |
209 | 209 |
210 <p>This is equivalent to the code:</p> | 210 <p>This is equivalent to the code:</p> |
211 | 211 |
212 <tt><pre> | 212 <p><tt><pre> |
213 local name = "Bob" | 213 local name = "Bob" |
214 write( "Hello ", name, "!" ) | 214 write( "Hello ", name, "!" ) |
215 </pre></tt> | 215 </pre></tt></p> |
216 | 216 |
217 <p>The strings in template expressions may be multiple lines.</p> | 217 <p>The strings in template expressions may be multiple lines.</p> |
218 | 218 |
219 </div> | 219 </div> |
220 | 220 |