comparison website/src/manual.html.luan @ 470:5627eb637eb4

documentation
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 09 May 2015 23:54:22 -0600
parents 85467f95ab13
children f4aca5a5346a
comparison
equal deleted inserted replaced
469:85467f95ab13 470:5627eb637eb4
85 85
86 <div margin-bottom="1em"> 86 <div margin-bottom="1em">
87 <a href="#libs">Standard Libraries</a> 87 <a href="#libs">Standard Libraries</a>
88 <ul> 88 <ul>
89 <li><a href="#default_lib">Default Environment</a></li> 89 <li><a href="#default_lib">Default Environment</a></li>
90 <li><a href="#luan_lib">Basic Functions</a></li>
90 </ul> 91 </ul>
91 </div> 92 </div>
92 93
93 <hr/> 94 <hr/>
94 95
1822 <h3 margin-top="1em"><a name="default_lib">Default Environment</a></h3> 1823 <h3 margin-top="1em"><a name="default_lib">Default Environment</a></h3>
1823 1824
1824 <p> 1825 <p>
1825 These are provided by default as local variables for any Luan code as described in <a href="#env">Environments</a>. 1826 These are provided by default as local variables for any Luan code as described in <a href="#env">Environments</a>.
1826 1827
1828
1827 <h4 margin-top="1em"><a name="_ENV"><tt>_ENV</tt></a></h4> 1829 <h4 margin-top="1em"><a name="_ENV"><tt>_ENV</tt></a></h4>
1828 1830
1829 <p> 1831 <p>
1830 This is a table that holds the global variables of a module as described in <a href="#env">Environments</a>. 1832 This is a table that holds the global variables of a module as described in <a href="#env">Environments</a>.
1831 1833
1832 1834
1833 1835 <h4 margin-top="1em"><a name="require"><tt>java ()</tt></a></h4>
1834 <h2>6.1 &ndash; <a name="6.1">Basic Functions</a></h2> 1836
1835 1837 <p>
1836 <p> 1838 This function enables Java in the current chunk if that chunk has permission to use Java. If the chunk doesn't have permission to use Java, then an error is thrown.
1837 The basic library provides core functions to Lua. 1839
1838 If you do not include this library in your application, 1840
1839 you should check carefully whether you need to provide 1841 <h4 margin-top="1em"><a name="require"><tt>require (mod_uri)</tt></a></h4>
1840 implementations for some of its facilities. 1842
1841 1843 <p>
1842 1844 Example use:
1843 <p> 1845
1844 <hr><h3><a name="pdf-assert"><code>assert (v [, message])</code></a></h3> 1846 <p><tt><pre>
1845 1847 local Table = require "luan:Table"
1846 1848 </pre></tt></p>
1847 <p> 1849
1848 Calls <a href="#pdf-error"><code>error</code></a> if 1850 <p>
1849 the value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>); 1851 Could be defined as:
1850 otherwise, returns all its arguments. 1852
1851 In case of error, 1853 <p><tt><pre>
1852 <code>message</code> is the error object; 1854 local function require(mod_name)
1853 when absent, it defaults to "<code>assertion failed!</code>" 1855 return Package.load(mod_name) or Luan.error("module '"..mod_name.."' not found")
1854 1856 end
1855 1857 </pre></tt></p>
1856 1858
1857 1859
1858 <p> 1860 <h3 margin-top="1em"><a name="luan_lib">Basic Functions</a></h3>
1859 <hr><h3><a name="pdf-collectgarbage"><code>collectgarbage ([opt [, arg]])</code></a></h3> 1861
1860 1862 <p>
1861 1863 Include this library by:
1862 <p> 1864
1863 This function is a generic interface to the garbage collector. 1865 <p><tt><pre>
1864 It performs different functions according to its first argument, <code>opt</code>: 1866 local Luan = require "luan:Luan"
1865 1867 </pre></tt></p>
1866 <ul> 1868
1867 1869 The basic library provides basic functions to Luan that don't depend on other libaries.
1868 <li><b>"<code>collect</code>": </b> 1870
1869 performs a full garbage-collection cycle. 1871
1870 This is the default option. 1872 <h4 margin-top="1em"><a name="Luan.assert"><tt>Luan.assert (v [, message])</tt></a></h4>
1871 </li> 1873
1872 1874 <p>
1873 <li><b>"<code>stop</code>": </b> 1875 Could be defined as:
1874 stops automatic execution of the garbage collector. 1876
1875 The collector will run only when explicitly invoked, 1877 <p><tt><pre>
1876 until a call to restart it. 1878 function Luan.assert(v,message)
1877 </li> 1879 return v or Luan.error(message or "assertion failed!")
1878 1880 end
1879 <li><b>"<code>restart</code>": </b> 1881 </pre></tt></p>
1880 restarts automatic execution of the garbage collector. 1882
1881 </li> 1883
1882 1884 <h4 margin-top="1em"><a name="Luan.assert_binary"><tt>Luan.assert_binary (v)</tt></a></h4>
1883 <li><b>"<code>count</code>": </b> 1885
1884 returns the total memory in use by Lua in Kbytes. 1886 <p>
1885 The value has a fractional part, 1887 Could be defined as:
1886 so that it multiplied by 1024 1888
1887 gives the exact number of bytes in use by Lua 1889 <p><tt><pre>
1888 (except for overflows). 1890 function Luan.assert_binary(v)
1889 </li> 1891 local v_type = Luan.type(v)
1890 1892 return v_type == "binary" and v or Luan.error("bad argument #1 (binary expected, got "..v_type..")")
1891 <li><b>"<code>step</code>": </b> 1893 end
1892 performs a garbage-collection step. 1894 </pre></tt></p>
1893 The step "size" is controlled by <code>arg</code>. 1895
1894 With a zero value, 1896
1895 the collector will perform one basic (indivisible) step. 1897 <h4 margin-top="1em"><a name="Luan.assert_boolean"><tt>Luan.assert_boolean (v)</tt></a></h4>
1896 For non-zero values, 1898
1897 the collector will perform as if that amount of memory 1899 <p>
1898 (in KBytes) had been allocated by Lua. 1900 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>boolean</tt>.
1899 Returns <b>true</b> if the step finished a collection cycle. 1901
1900 </li> 1902
1901 1903 <h4 margin-top="1em"><a name="Luan.assert_integer"><tt>Luan.assert_integer (v)</tt></a></h4>
1902 <li><b>"<code>setpause</code>": </b> 1904
1903 sets <code>arg</code> as the new value for the <em>pause</em> of 1905 <p>
1904 the collector (see <a href="#2.5">&sect;2.5</a>). 1906 Asserts that <tt>v</tt> can be converted to Java type <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html">Integer</a> and returns an Integer.
1905 Returns the previous value for <em>pause</em>. 1907
1906 </li> 1908
1907 1909 <h4 margin-top="1em"><a name="Luan.assert_long"><tt>Luan.assert_long (v)</tt></a></h4>
1908 <li><b>"<code>setstepmul</code>": </b> 1910
1909 sets <code>arg</code> as the new value for the <em>step multiplier</em> of 1911 <p>
1910 the collector (see <a href="#2.5">&sect;2.5</a>). 1912 Asserts that <tt>v</tt> can be converted to Java type <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html">Long</a> and returns a Long.
1911 Returns the previous value for <em>step</em>. 1913
1912 </li> 1914
1913 1915 <h4 margin-top="1em"><a name="Luan.assert_number"><tt>Luan.assert_number (v)</tt></a></h4>
1914 <li><b>"<code>isrunning</code>": </b> 1916
1915 returns a boolean that tells whether the collector is running 1917 <p>
1916 (i.e., not stopped). 1918 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>number</tt>.
1917 </li> 1919
1918 1920
1919 </ul> 1921 <h4 margin-top="1em"><a name="Luan.assert_string"><tt>Luan.assert_string (v)</tt></a></h4>
1920 1922
1921 1923 <p>
1922 1924 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>string</tt>.
1923 <p> 1925
1924 <hr><h3><a name="pdf-dofile"><code>dofile ([filename])</code></a></h3> 1926
1925 Opens the named file and executes its contents as a Lua chunk. 1927 <h4 margin-top="1em"><a name="Luan.assert_table"><tt>Luan.assert_table (v)</tt></a></h4>
1926 When called without arguments, 1928
1927 <code>dofile</code> executes the contents of the standard input (<code>stdin</code>). 1929 <p>
1928 Returns all values returned by the chunk. 1930 Like <a href="#Luan.assert_binary"><tt>assert_binary</tt></a> but for type <tt>table</tt>.
1929 In case of errors, <code>dofile</code> propagates the error 1931
1930 to its caller (that is, <code>dofile</code> does not run in protected mode). 1932
1931 1933 <h4 margin-top="1em"><a name="Luan.do_file"><tt>Luan.do_file ([uri])</tt></a></h4>
1932 1934
1933 1935 <p>
1934 1936 Could be defined as:
1935 <p> 1937
1936 <hr><h3><a name="pdf-error"><code>error (message [, level])</code></a></h3> 1938 <p><tt><pre>
1937 Terminates the last protected function called 1939 function Luan.do_file(uri)
1938 and returns <code>message</code> as the error object. 1940 return load_file(uri)()
1939 Function <code>error</code> never returns. 1941 end
1940 1942 </pre></tt></p>
1941 1943
1942 <p> 1944
1943 Usually, <code>error</code> adds some information about the error position 1945
1944 at the beginning of the message, if the message is a string. 1946 <h4 margin-top="1em"><a name="Luan.error"><tt>Luan.error (message)</tt></a></h4>
1945 The <code>level</code> argument specifies how to get the error position. 1947
1946 With level&nbsp;1 (the default), the error position is where the 1948 <p>
1947 <code>error</code> function was called. 1949 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 Level&nbsp;2 points the error to where the function 1950
1949 that called <code>error</code> was called; and so on. 1951
1950 Passing a level&nbsp;0 avoids the addition of error position information 1952 <h4 margin-top="1em"><a name="Luan.get_metatable"><tt>Luan.get_metatable (table)</tt></a></h4>
1951 to the message. 1953
1952 1954 <p>
1953 1955 If <tt>table</tt> does not have a metatable, returns <b>nil</b>.
1954
1955
1956 <p>
1957 <hr><h3><a name="pdf-_G"><code>_G</code></a></h3>
1958 A global variable (not a function) that
1959 holds the global environment (see <a href="#2.2">&sect;2.2</a>).
1960 Lua itself does not use this variable;
1961 changing its value does not affect any environment,
1962 nor vice versa.
1963
1964
1965
1966
1967 <p>
1968 <hr><h3><a name="pdf-getmetatable"><code>getmetatable (object)</code></a></h3>
1969
1970
1971 <p>
1972 If <code>object</code> does not have a metatable, returns <b>nil</b>.
1973 Otherwise, 1956 Otherwise,
1974 if the object's metatable has a <code>"__metatable"</code> field, 1957 if the table's metatable has a <tt>"__metatable"</tt> field,
1975 returns the associated value. 1958 returns the associated value.
1976 Otherwise, returns the metatable of the given object. 1959 Otherwise, returns the metatable of the given table.
1977 1960
1978 1961
1979 1962
1980 1963
1981 <p> 1964 <p>