Mercurial Hosting > luan
comparison website/src/manual.html.luan @ 482:7e9fcfbf22ec
documentation
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 11 May 2015 21:05:10 -0600 |
parents | 1285c52ea9d4 |
children | ddee9f5167d8 |
comparison
equal
deleted
inserted
replaced
481:5d4a78c93383 | 482:7e9fcfbf22ec |
---|---|
276 to call a given function in <i>protected mode</i>. | 276 to call a given function in <i>protected mode</i>. |
277 | 277 |
278 | 278 |
279 <p> | 279 <p> |
280 Whenever there is an error, | 280 Whenever there is an error, |
281 an <i>error object</i> (also called an <i>error message</i>) | 281 an <i>error table</i> |
282 is propagated with information about the error. | 282 is propagated with information about the error. |
283 Luan itself only generates errors whose error object is a string, | 283 See <a href="#Luan.new_error"><tt>Luan.new_error</tt></a>. |
284 but programs may generate errors with | |
285 any value as the error object. | |
286 It is up to the Luan program or its host to handle such error objects. | |
287 | |
288 | |
289 | 284 |
290 | 285 |
291 | 286 |
292 <h3 <%=heading_options%> ><a name="meta">Metatables and Metamethods</a></h3> | 287 <h3 <%=heading_options%> ><a name="meta">Metatables and Metamethods</a></h3> |
293 | 288 |
1948 | 1943 |
1949 | 1944 |
1950 <h4 <%=heading_options%> ><a name="Luan.error"><tt>Luan.error (message)</tt></a></h4> | 1945 <h4 <%=heading_options%> ><a name="Luan.error"><tt>Luan.error (message)</tt></a></h4> |
1951 | 1946 |
1952 <p> | 1947 <p> |
1953 Throws an error containing the message. This uses Java exceptions internally and the implementation is likely to change. So this documentation is likely to change. | 1948 Throws an error containing the message. |
1949 | |
1950 <p> | |
1951 Could be defined as: | |
1952 | |
1953 <p><tt><pre> | |
1954 function Luan.error(message) | |
1955 <a href="#Luan.new_error">Luan.new_error</a>(message).throw() | |
1956 end | |
1957 </pre></tt></p> | |
1958 | |
1954 | 1959 |
1955 | 1960 |
1956 <h4 <%=heading_options%> ><a name="Luan.get_metatable"><tt>Luan.get_metatable (table)</tt></a></h4> | 1961 <h4 <%=heading_options%> ><a name="Luan.get_metatable"><tt>Luan.get_metatable (table)</tt></a></h4> |
1957 | 1962 |
1958 <p> | 1963 <p> |
2034 f.exists() or <a href="#Luan.error">Luan.error</a>("file '"..file_uri.."' not found") | 2039 f.exists() or <a href="#Luan.error">Luan.error</a>("file '"..file_uri.."' not found") |
2035 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri ) | 2040 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri ) |
2036 end | 2041 end |
2037 </pre></tt></p> | 2042 </pre></tt></p> |
2038 | 2043 |
2044 | |
2045 <h4 <%=heading_options%> ><a name="Luan.new_error"><tt>Luan.new_error (message)</tt></a></h4> | |
2046 | |
2047 <p> | |
2048 Creates a new error table containing the message assigned to "<tt>message</tt>". The error table also contains a <tt>throw</tt> function which throws the error. The table also contains a list of stack trace elements where each stack trace element is a table containing "<tt>source</tt>", "<tt>line</tt>", and possible "<tt>call_to</tt>". The table also has a metatable containing "<tt>__to_string</tt>" to render the error. | |
2049 | |
2050 <p> | |
2051 To print the current stack trace, you could do: | |
2052 | |
2053 <p><tt><pre> | |
2054 Io.print( Luan.new_error "stack" ) | |
2055 </pre></tt></p> | |
2039 | 2056 |
2040 | 2057 |
2041 <h4 <%=heading_options%> ><a name="Luan.pairs"><tt>Luan.pairs (t)</tt></a></h4> | 2058 <h4 <%=heading_options%> ><a name="Luan.pairs"><tt>Luan.pairs (t)</tt></a></h4> |
2042 | 2059 |
2043 <p> | 2060 <p> |
2252 -- clean up | 2269 -- clean up |
2253 end; | 2270 end; |
2254 } | 2271 } |
2255 </pre></tt></p> | 2272 </pre></tt></p> |
2256 | 2273 |
2274 <p> | |
2275 Could be defined as: | |
2276 | |
2277 <p><tt><pre> | |
2278 function Luan.try(t) | |
2279 local r = { <a href="#Luan.pcall">Luan.pcall</a>(t[1]) } | |
2280 if r[1] then | |
2281 Table.remove(r,1) | |
2282 elseif t.catch ~= nil then | |
2283 r = { t.catch(r[2]) } | |
2284 else | |
2285 t.finally and t.finally() | |
2286 r[2].throw() | |
2287 end | |
2288 t.finally and t.finally() | |
2289 return Table.unpack(r) | |
2290 end | |
2291 </pre></tt></p> | |
2257 | 2292 |
2258 | 2293 |
2259 <h4 <%=heading_options%> ><a name="Luan.type"><tt>Luan.type (v)</tt></a></h4> | 2294 <h4 <%=heading_options%> ><a name="Luan.type"><tt>Luan.type (v)</tt></a></h4> |
2260 | 2295 |
2261 <p> | 2296 <p> |