Mercurial Hosting > luan
comparison website/src/manual.html.luan @ 478:eb6d90fb0b5c
documentation
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Mon, 11 May 2015 15:06:46 -0600 |
| parents | cd22e4694ea3 |
| children | 1285c52ea9d4 |
comparison
equal
deleted
inserted
replaced
| 477:b8ddd55c9b11 | 478:eb6d90fb0b5c |
|---|---|
| 1 local Luan = require "luan:Luan" | |
| 1 local Io = require "luan:Io" | 2 local Io = require "luan:Io" |
| 2 local Html = require "luan:Html" | 3 local Html = require "luan:Html" |
| 3 local Http = require "luan:web/Http" | 4 local Http = require "luan:web/Http" |
| 4 local Shared = require "site:/Shared" | 5 local Shared = require "site:/Shared" |
| 5 | 6 |
| 218 always manipulate references to values; | 219 always manipulate references to values; |
| 219 these operations do not imply any kind of copy. | 220 these operations do not imply any kind of copy. |
| 220 | 221 |
| 221 | 222 |
| 222 <p> | 223 <p> |
| 223 The library function <a href="#pdf-type"><tt>Luan.type</tt></a> returns a string describing the type | 224 The library function <a href="#Luan.type"><tt>Luan.type</tt></a> returns a string describing the type |
| 224 of a given value (see <a href="#6.1">§6.1</a>). | 225 of a given value. |
| 225 | 226 |
| 226 | 227 |
| 227 | 228 |
| 228 | 229 |
| 229 | 230 |
| 266 | 267 |
| 267 <h3 margin-top="1em"><a name="error">Error Handling</a></h3> | 268 <h3 margin-top="1em"><a name="error">Error Handling</a></h3> |
| 268 | 269 |
| 269 <p> | 270 <p> |
| 270 Luan code can explicitly generate an error by calling the | 271 Luan code can explicitly generate an error by calling the |
| 271 <a href="#pdf-error"><tt>error</tt></a> function. | 272 <a href="#Luan.error"><tt>error</tt></a> function. |
| 272 If you need to catch errors in Luan, | 273 If you need to catch errors in Luan, |
| 273 you can use <a href="#pdf-pcall"><tt>pcall</tt></a> or <a href="#pdf-xpcall"><tt>try</tt></a> | 274 you can use <a href="#Luan.pcall"><tt>pcall</tt></a> or <a href="#Luan.try"><tt>try</tt></a> |
| 274 to call a given function in <i>protected mode</i>. | 275 to call a given function in <i>protected mode</i>. |
| 275 | 276 |
| 276 | 277 |
| 277 <p> | 278 <p> |
| 278 Whenever there is an error, | 279 Whenever there is an error, |
| 309 and the metamethod is the function that performs the addition. | 310 and the metamethod is the function that performs the addition. |
| 310 | 311 |
| 311 | 312 |
| 312 <p> | 313 <p> |
| 313 You can query the metatable of any table | 314 You can query the metatable of any table |
| 314 using the <a href="#pdf-getmetatable"><tt>get_metatable</tt></a> function. | 315 using the <a href="#Luan.get_metatable"><tt>get_metatable</tt></a> function. |
| 315 | 316 |
| 316 | 317 |
| 317 <p> | 318 <p> |
| 318 You can replace the metatable of tables | 319 You can replace the metatable of tables |
| 319 using the <a href="#pdf-setmetatable"><tt>set_metatable</tt></a> function. | 320 using the <a href="#Luan.set_metatable"><tt>set_metatable</tt></a> function. |
| 320 | 321 |
| 321 | 322 |
| 322 <p> | 323 <p> |
| 323 A metatable controls how a table behaves in | 324 A metatable controls how a table behaves in |
| 324 arithmetic operations, bitwise operations, | 325 arithmetic operations, bitwise operations, |
| 490 | 491 |
| 491 <p> | 492 <p> |
| 492 Whenever there is a "new_index" metamethod, | 493 Whenever there is a "new_index" metamethod, |
| 493 Luan does not perform the primitive assignment. | 494 Luan does not perform the primitive assignment. |
| 494 (If necessary, | 495 (If necessary, |
| 495 the metamethod itself can call <a href="#pdf-rawset"><tt>raw_set</tt></a> | 496 the metamethod itself can call <a href="#Luan.raw_set"><tt>raw_set</tt></a> |
| 496 to do the assignment.) | 497 to do the assignment.) |
| 497 </li> | 498 </li> |
| 498 | 499 |
| 499 <li><b>"call": </b> | 500 <li><b>"call": </b> |
| 500 The call operation <tt>func(args)</tt>. | 501 The call operation <tt>func(args)</tt>. |
| 1815 <p> | 1816 <p> |
| 1816 The standard Luan libraries provide useful functions | 1817 The standard Luan libraries provide useful functions |
| 1817 that are implemented both in Java and in Luan itself. | 1818 that are implemented both in Java and in Luan itself. |
| 1818 How each function is implemented shouldn't matter to the user. | 1819 How each function is implemented shouldn't matter to the user. |
| 1819 Some of these functions provide essential services to the language | 1820 Some of these functions provide essential services to the language |
| 1820 (e.g., <a href="#pdf-type"><tt>type</tt></a> and <a href="#pdf-getmetatable"><tt>get_metatable</tt></a>); | 1821 (e.g., <a href="#Luan.type"><tt>type</tt></a> and <a href="#Luan.get_metatable"><tt>get_metatable</tt></a>); |
| 1821 others provide access to "outside" services (e.g., I/O). | 1822 others provide access to "outside" services (e.g., I/O). |
| 1822 | 1823 |
| 1823 | 1824 |
| 1824 <h3 margin-top="1em"><a name="default_lib">Default Environment</a></h3> | 1825 <h3 margin-top="1em"><a name="default_lib">Default Environment</a></h3> |
| 1825 | 1826 |
| 2109 Could be defined as: | 2110 Could be defined as: |
| 2110 | 2111 |
| 2111 <p><tt><pre> | 2112 <p><tt><pre> |
| 2112 function Luan.range(start, stop, step) | 2113 function Luan.range(start, stop, step) |
| 2113 step = step or 1 | 2114 step = step or 1 |
| 2114 step == 0 and Luan.error "bad argument #3 (step may not be zero)" | 2115 step == 0 and <a href="#Luan.error">Luan.error</a> "bad argument #3 (step may not be zero)" |
| 2115 local i = start | 2116 local i = start |
| 2116 return function() | 2117 return function() |
| 2117 if step > 0 and i <= stop or step < 0 and i >= stop then | 2118 if step > 0 and i <= stop or step < 0 and i >= stop then |
| 2118 local rtn = i | 2119 local rtn = i |
| 2119 i = i + step | 2120 i = i + step |
| 2286 <h4 margin-top="1em"><a name="Luan.VERSION"><tt>Luan.VERSION</tt></a></h4> | 2287 <h4 margin-top="1em"><a name="Luan.VERSION"><tt>Luan.VERSION</tt></a></h4> |
| 2287 | 2288 |
| 2288 <p> | 2289 <p> |
| 2289 A global variable (not a function) that | 2290 A global variable (not a function) that |
| 2290 holds a string containing the current interpreter version. | 2291 holds a string containing the current interpreter version. |
| 2291 The current value of this variable is "<tt>Luan 0.8</tt>". | 2292 The current value of this variable is "<tt><%=Luan.VERSION%></tt>". |
| 2292 | 2293 |
| 2293 | 2294 |
| 2294 | 2295 |
| 2295 | 2296 |
| 2296 | 2297 |
