Mercurial Hosting > luan
comparison website/src/manual.html.luan @ 642:c4216a583de4 0.17
add links to functions in manual
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 23 Mar 2016 15:07:06 -0600 |
parents | 35dde32c02ab |
children | 1e4b0bc0202d |
comparison
equal
deleted
inserted
replaced
641:252041bc41b5 | 642:c4216a583de4 |
---|---|
1834 | 1834 |
1835 <p> | 1835 <p> |
1836 The basic library provides basic functions to Luan that don't depend on other libaries. | 1836 The basic library provides basic functions to Luan that don't depend on other libaries. |
1837 | 1837 |
1838 | 1838 |
1839 <h4 heading><a name="Luan.assert"><code>Luan.assert (v [, message])</code></a></h4> | 1839 <h4 heading><a name="Luan.assert" href="#Luan.assert"><code>Luan.assert (v [, message])</code></a></h4> |
1840 | 1840 |
1841 <p> | 1841 <p> |
1842 Could be defined as: | 1842 Could be defined as: |
1843 | 1843 |
1844 <pre> | 1844 <pre> |
1846 return v or <a href="#Luan.error">Luan.error</a>(message or "assertion failed!") | 1846 return v or <a href="#Luan.error">Luan.error</a>(message or "assertion failed!") |
1847 end | 1847 end |
1848 </pre> | 1848 </pre> |
1849 | 1849 |
1850 | 1850 |
1851 <h4 heading><a name="Luan.assert_binary"><code>Luan.assert_binary (v)</code></a></h4> | 1851 <h4 heading><a name="Luan.assert_binary" href="#Luan.assert_binary"><code>Luan.assert_binary (v)</code></a></h4> |
1852 | 1852 |
1853 <p> | 1853 <p> |
1854 Could be defined as: | 1854 Could be defined as: |
1855 | 1855 |
1856 <pre> | 1856 <pre> |
1859 return v_type == "binary" and v or <a href="#Luan.error">Luan.error</a>("bad argument #1 (binary expected, got "..v_type..")") | 1859 return v_type == "binary" and v or <a href="#Luan.error">Luan.error</a>("bad argument #1 (binary expected, got "..v_type..")") |
1860 end | 1860 end |
1861 </pre> | 1861 </pre> |
1862 | 1862 |
1863 | 1863 |
1864 <h4 heading><a name="Luan.assert_boolean"><code>Luan.assert_boolean (v)</code></a></h4> | 1864 <h4 heading><a name="Luan.assert_boolean" href="#Luan.assert_boolean"><code>Luan.assert_boolean (v)</code></a></h4> |
1865 | 1865 |
1866 <p> | 1866 <p> |
1867 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>boolean</code>. | 1867 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>boolean</code>. |
1868 | 1868 |
1869 | 1869 |
1870 <h4 heading><a name="Luan.assert_function"><code>Luan.assert_function (v)</code></a></h4> | 1870 <h4 heading><a name="Luan.assert_function" href="#Luan.assert_function"><code>Luan.assert_function (v)</code></a></h4> |
1871 | 1871 |
1872 <p> | 1872 <p> |
1873 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>function</code>. | 1873 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>function</code>. |
1874 | 1874 |
1875 | 1875 |
1876 <h4 heading><a name="Luan.assert_integer"><code>Luan.assert_integer (v)</code></a></h4> | 1876 <h4 heading><a name="Luan.assert_integer" href="#Luan.assert_integer"><code>Luan.assert_integer (v)</code></a></h4> |
1877 | 1877 |
1878 <p> | 1878 <p> |
1879 Asserts that <code>v</code> 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. | 1879 Asserts that <code>v</code> 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. |
1880 | 1880 |
1881 | 1881 |
1882 <h4 heading><a name="Luan.assert_long"><code>Luan.assert_long (v)</code></a></h4> | 1882 <h4 heading><a name="Luan.assert_long" href="#Luan.assert_long"><code>Luan.assert_long (v)</code></a></h4> |
1883 | 1883 |
1884 <p> | 1884 <p> |
1885 Asserts that <code>v</code> 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. | 1885 Asserts that <code>v</code> 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. |
1886 | 1886 |
1887 | 1887 |
1888 <h4 heading><a name="Luan.assert_number"><code>Luan.assert_number (v)</code></a></h4> | 1888 <h4 heading><a name="Luan.assert_number" href="#Luan.assert_number"><code>Luan.assert_number (v)</code></a></h4> |
1889 | 1889 |
1890 <p> | 1890 <p> |
1891 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>number</code>. | 1891 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>number</code>. |
1892 | 1892 |
1893 | 1893 |
1894 <h4 heading><a name="Luan.assert_string"><code>Luan.assert_string (v)</code></a></h4> | 1894 <h4 heading><a name="Luan.assert_string" href="#Luan.assert_string"><code>Luan.assert_string (v)</code></a></h4> |
1895 | 1895 |
1896 <p> | 1896 <p> |
1897 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>string</code>. | 1897 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>string</code>. |
1898 | 1898 |
1899 | 1899 |
1900 <h4 heading><a name="Luan.assert_table"><code>Luan.assert_table (v)</code></a></h4> | 1900 <h4 heading><a name="Luan.assert_table" href="#Luan.assert_table"><code>Luan.assert_table (v)</code></a></h4> |
1901 | 1901 |
1902 <p> | 1902 <p> |
1903 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>table</code>. | 1903 Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>table</code>. |
1904 | 1904 |
1905 | 1905 |
1906 <h4 heading><a name="Luan.do_file"><code>Luan.do_file ([uri])</code></a></h4> | 1906 <h4 heading><a name="Luan.do_file" href="#Luan.do_file"><code>Luan.do_file ([uri])</code></a></h4> |
1907 | 1907 |
1908 <p> | 1908 <p> |
1909 Could be defined as: | 1909 Could be defined as: |
1910 | 1910 |
1911 <pre> | 1911 <pre> |
1914 end | 1914 end |
1915 </pre> | 1915 </pre> |
1916 | 1916 |
1917 | 1917 |
1918 | 1918 |
1919 <h4 heading><a name="Luan.error"><code>Luan.error (message)</code></a></h4> | 1919 <h4 heading><a name="Luan.error" href="#Luan.error"><code>Luan.error (message)</code></a></h4> |
1920 | 1920 |
1921 <p> | 1921 <p> |
1922 Throws an error containing the message. | 1922 Throws an error containing the message. |
1923 | 1923 |
1924 <p> | 1924 <p> |
1930 end | 1930 end |
1931 </pre> | 1931 </pre> |
1932 | 1932 |
1933 | 1933 |
1934 | 1934 |
1935 <h4 heading><a name="Luan.get_metatable"><code>Luan.get_metatable (table)</code></a></h4> | 1935 <h4 heading><a name="Luan.get_metatable" href="#Luan.get_metatable"><code>Luan.get_metatable (table)</code></a></h4> |
1936 | 1936 |
1937 <p> | 1937 <p> |
1938 If <code>table</code> does not have a metatable, returns <b>nil</b>. | 1938 If <code>table</code> does not have a metatable, returns <b>nil</b>. |
1939 Otherwise, | 1939 Otherwise, |
1940 if the table's metatable has a <code>"__metatable"</code> field, | 1940 if the table's metatable has a <code>"__metatable"</code> field, |
1941 returns the associated value. | 1941 returns the associated value. |
1942 Otherwise, returns the metatable of the given table. | 1942 Otherwise, returns the metatable of the given table. |
1943 | 1943 |
1944 | 1944 |
1945 <h4 heading><a name="Luan.ipairs"><code>Luan.ipairs (t)</code></a></h4> | 1945 <h4 heading><a name="Luan.ipairs" href="#Luan.ipairs"><code>Luan.ipairs (t)</code></a></h4> |
1946 | 1946 |
1947 <p> | 1947 <p> |
1948 Returns an iterator function | 1948 Returns an iterator function |
1949 so that the construction | 1949 so that the construction |
1950 | 1950 |
1972 end | 1972 end |
1973 </pre> | 1973 </pre> |
1974 | 1974 |
1975 | 1975 |
1976 | 1976 |
1977 <h4 heading><a name="Luan.load"><code>Luan.load (text, [source_name [env, [, allow_expression]]])</code></a></h4> | 1977 <h4 heading><a name="Luan.load" href="#Luan.load"><code>Luan.load (text, [source_name [env, [, allow_expression]]])</code></a></h4> |
1978 | 1978 |
1979 <p> | 1979 <p> |
1980 Loads a chunk. | 1980 Loads a chunk. |
1981 | 1981 |
1982 <p> | 1982 <p> |
1993 | 1993 |
1994 <p> | 1994 <p> |
1995 If the <code>allow_expression</code> parameter is <code>true</code> then the entire text can be nothing more than an expression in which case the chunk returns the value of this expression. | 1995 If the <code>allow_expression</code> parameter is <code>true</code> then the entire text can be nothing more than an expression in which case the chunk returns the value of this expression. |
1996 | 1996 |
1997 | 1997 |
1998 <h4 heading><a name="Luan.load_file"><code>Luan.load_file (file_uri [, add_extension])</code></a></h4> | 1998 <h4 heading><a name="Luan.load_file" href="#Luan.load_file"><code>Luan.load_file (file_uri [, add_extension])</code></a></h4> |
1999 | 1999 |
2000 <p> | 2000 <p> |
2001 Similar to <a href="#Luan.load"><code>load</code></a>, | 2001 Similar to <a href="#Luan.load"><code>load</code></a>, |
2002 but gets the chunk from file <code>file_uri</code> | 2002 but gets the chunk from file <code>file_uri</code> |
2003 or from the standard input, | 2003 or from the standard input, |
2014 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri ) | 2014 return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri ) |
2015 end | 2015 end |
2016 </pre> | 2016 </pre> |
2017 | 2017 |
2018 | 2018 |
2019 <h4 heading><a name="Luan.new_error"><code>Luan.new_error (message)</code></a></h4> | 2019 <h4 heading><a name="Luan.new_error" href="#Luan.new_error"><code>Luan.new_error (message)</code></a></h4> |
2020 | 2020 |
2021 <p> | 2021 <p> |
2022 Creates a new error table containing the message assigned to "<code>message</code>". The error table also contains a <code>throw</code> function which throws the error. The table also contains a list of stack trace elements where each stack trace element is a table containing "<code>source</code>", "<code>line</code>", and possible "<code>call_to</code>". The table also has a metatable containing "<code>__to_string</code>" to render the error. | 2022 Creates a new error table containing the message assigned to "<code>message</code>". The error table also contains a <code>throw</code> function which throws the error. The table also contains a list of stack trace elements where each stack trace element is a table containing "<code>source</code>", "<code>line</code>", and possible "<code>call_to</code>". The table also has a metatable containing "<code>__to_string</code>" to render the error. |
2023 | 2023 |
2024 <p> | 2024 <p> |
2027 <pre> | 2027 <pre> |
2028 Io.print( Luan.new_error "stack" ) | 2028 Io.print( Luan.new_error "stack" ) |
2029 </pre> | 2029 </pre> |
2030 | 2030 |
2031 | 2031 |
2032 <h4 heading><a name="Luan.pairs"><code>Luan.pairs (t)</code></a></h4> | 2032 <h4 heading><a name="Luan.pairs" href="#Luan.pairs"><code>Luan.pairs (t)</code></a></h4> |
2033 | 2033 |
2034 <p> | 2034 <p> |
2035 If <code>t</code> has a metamethod <code>__pairs</code>, | 2035 If <code>t</code> has a metamethod <code>__pairs</code>, |
2036 calls it with <code>t</code> as argument and returns the | 2036 calls it with <code>t</code> as argument and returns the |
2037 result from the call. | 2037 result from the call. |
2049 <p> | 2049 <p> |
2050 will iterate over all key–value pairs of table <code>t</code>. | 2050 will iterate over all key–value pairs of table <code>t</code>. |
2051 | 2051 |
2052 | 2052 |
2053 | 2053 |
2054 <h4 heading><a name="Luan.pcall"><code>Luan.pcall (f [, arg1, ···])</code></a></h4> | 2054 <h4 heading><a name="Luan.pcall" href="#Luan.pcall"><code>Luan.pcall (f [, arg1, ···])</code></a></h4> |
2055 | 2055 |
2056 <p> | 2056 <p> |
2057 Calls function <code>f</code> with | 2057 Calls function <code>f</code> with |
2058 the given arguments in <em>protected mode</em>. | 2058 the given arguments in <em>protected mode</em>. |
2059 This means that any error inside <code>f</code> is not propagated; | 2059 This means that any error inside <code>f</code> is not propagated; |
2079 For complete control over the output, | 2079 For complete control over the output, |
2080 use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>io.write</code></a>. | 2080 use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>io.write</code></a>. |
2081 | 2081 |
2082 | 2082 |
2083 | 2083 |
2084 <h4 heading><a name="Luan.range"><code>Luan.range (start, stop [, step])</code></a></h4> | 2084 <h4 heading><a name="Luan.range" href="#Luan.range"><code>Luan.range (start, stop [, step])</code></a></h4> |
2085 | 2085 |
2086 <p> | 2086 <p> |
2087 Based on <a href="https://docs.python.org/2/library/functions.html#range">the Python range() function</a>, this lets one iterate through a sequence of numbers. | 2087 Based on <a href="https://docs.python.org/2/library/functions.html#range">the Python range() function</a>, this lets one iterate through a sequence of numbers. |
2088 | 2088 |
2089 <p> | 2089 <p> |
2116 end | 2116 end |
2117 </pre> | 2117 </pre> |
2118 | 2118 |
2119 | 2119 |
2120 | 2120 |
2121 <h4 heading><a name="Luan.raw_equal"><code>Luan.raw_equal (v1, v2)</code></a></h4> | 2121 <h4 heading><a name="Luan.raw_equal" href="#Luan.raw_equal"><code>Luan.raw_equal (v1, v2)</code></a></h4> |
2122 | 2122 |
2123 <p> | 2123 <p> |
2124 Checks whether <code>v1</code> is equal to <code>v2</code>, | 2124 Checks whether <code>v1</code> is equal to <code>v2</code>, |
2125 without invoking any metamethod. | 2125 without invoking any metamethod. |
2126 Returns a boolean. | 2126 Returns a boolean. |
2127 | 2127 |
2128 | 2128 |
2129 | 2129 |
2130 <h4 heading><a name="Luan.raw_get"><code>Luan.raw_get (table, index)</code></a></h4> | 2130 <h4 heading><a name="Luan.raw_get" href="#Luan.raw_get"><code>Luan.raw_get (table, index)</code></a></h4> |
2131 | 2131 |
2132 <p> | 2132 <p> |
2133 Gets the real value of <code>table[index]</code>, | 2133 Gets the real value of <code>table[index]</code>, |
2134 without invoking any metamethod. | 2134 without invoking any metamethod. |
2135 <code>table</code> must be a table; | 2135 <code>table</code> must be a table; |
2136 <code>index</code> may be any value. | 2136 <code>index</code> may be any value. |
2137 | 2137 |
2138 | 2138 |
2139 | 2139 |
2140 <h4 heading><a name="Luan.raw_len"><code>Luan.raw_len (v)</code></a></h4> | 2140 <h4 heading><a name="Luan.raw_len" href="#Luan.raw_len"><code>Luan.raw_len (v)</code></a></h4> |
2141 | 2141 |
2142 <p> | 2142 <p> |
2143 Returns the length of the object <code>v</code>, | 2143 Returns the length of the object <code>v</code>, |
2144 which must be a table or a string, | 2144 which must be a table or a string, |
2145 without invoking any metamethod. | 2145 without invoking any metamethod. |
2146 Returns an integer. | 2146 Returns an integer. |
2147 | 2147 |
2148 | 2148 |
2149 | 2149 |
2150 <h4 heading><a name="Luan.raw_set"><code>Luan.raw_set (table, index, value)</code></a></h4> | 2150 <h4 heading><a name="Luan.raw_set" href="#Luan.raw_set"><code>Luan.raw_set (table, index, value)</code></a></h4> |
2151 | 2151 |
2152 <p> | 2152 <p> |
2153 Sets the real value of <code>table[index]</code> to <code>value</code>, | 2153 Sets the real value of <code>table[index]</code> to <code>value</code>, |
2154 without invoking any metamethod. | 2154 without invoking any metamethod. |
2155 <code>table</code> must be a table, | 2155 <code>table</code> must be a table, |
2156 <code>index</code> any value different from <b>nil</b>, | 2156 <code>index</code> any value different from <b>nil</b>, |
2157 and <code>value</code> any Lua value. | 2157 and <code>value</code> any Lua value. |
2158 | 2158 |
2159 | 2159 |
2160 <h4 heading><a name="Luan.set_metatable"><code>Luan.set_metatable (table, metatable)</code></a></h4> | 2160 <h4 heading><a name="Luan.set_metatable" href="#Luan.set_metatable"><code>Luan.set_metatable (table, metatable)</code></a></h4> |
2161 | 2161 |
2162 <p> | 2162 <p> |
2163 Sets the metatable for the given table. | 2163 Sets the metatable for the given table. |
2164 If <code>metatable</code> is <b>nil</b>, | 2164 If <code>metatable</code> is <b>nil</b>, |
2165 removes the metatable of the given table. | 2165 removes the metatable of the given table. |
2166 If the original metatable has a <code>"__metatable"</code> field, | 2166 If the original metatable has a <code>"__metatable"</code> field, |
2167 raises an error. | 2167 raises an error. |
2168 | 2168 |
2169 | 2169 |
2170 | 2170 |
2171 <h4 heading><a name="Luan.to_string"><code>Luan.to_string (v)</code></a></h4> | 2171 <h4 heading><a name="Luan.to_string" href="#Luan.to_string"><code>Luan.to_string (v)</code></a></h4> |
2172 | 2172 |
2173 <p> | 2173 <p> |
2174 Receives a value of any type and | 2174 Receives a value of any type and |
2175 converts it to a string in a human-readable format. | 2175 converts it to a string in a human-readable format. |
2176 | 2176 |
2180 with <code>v</code> as argument, | 2180 with <code>v</code> as argument, |
2181 and uses the result of the call as its result. | 2181 and uses the result of the call as its result. |
2182 | 2182 |
2183 | 2183 |
2184 | 2184 |
2185 <h4 heading><a name="Luan.try"><code>Luan.try (t, ···)</code></a></h4> | 2185 <h4 heading><a name="Luan.try" href="#Luan.try"><code>Luan.try (t, ···)</code></a></h4> |
2186 | 2186 |
2187 <p> | 2187 <p> |
2188 Implements try-catch as found in other languages where each block is in table <code>t</code>. <code>t[1]</code> is the "try" block. The <code>t.catch</code> and <code>t.finally</code> blocks are optional. Any extra arguments are passed to the "try" function. Returns the result of the "try" block or the "catch" block. | 2188 Implements try-catch as found in other languages where each block is in table <code>t</code>. <code>t[1]</code> is the "try" block. The <code>t.catch</code> and <code>t.finally</code> blocks are optional. Any extra arguments are passed to the "try" function. Returns the result of the "try" block or the "catch" block. |
2189 | 2189 |
2190 <p> | 2190 <p> |
2222 return Table.unpack(r) | 2222 return Table.unpack(r) |
2223 end | 2223 end |
2224 </pre> | 2224 </pre> |
2225 | 2225 |
2226 | 2226 |
2227 <h4 heading><a name="Luan.type"><code>Luan.type (v)</code></a></h4> | 2227 <h4 heading><a name="Luan.type" href="#Luan.type"><code>Luan.type (v)</code></a></h4> |
2228 | 2228 |
2229 <p> | 2229 <p> |
2230 Returns the type of its only argument, coded as a string. | 2230 Returns the type of its only argument, coded as a string. |
2231 The possible results of this function are | 2231 The possible results of this function are |
2232 "<code>nil</code>" (a string, not the value <b>nil</b>), | 2232 "<code>nil</code>" (a string, not the value <b>nil</b>), |
2237 "<code>table</code>", | 2237 "<code>table</code>", |
2238 "<code>function</code>", | 2238 "<code>function</code>", |
2239 and "<code>java</code>". | 2239 and "<code>java</code>". |
2240 | 2240 |
2241 | 2241 |
2242 <h4 heading><a name="Luan.values"><code>Luan.values (···)</code></a></h4> | 2242 <h4 heading><a name="Luan.values" href="#Luan.values"><code>Luan.values (···)</code></a></h4> |
2243 | 2243 |
2244 <p> | 2244 <p> |
2245 Returns a function so that the construction | 2245 Returns a function so that the construction |
2246 | 2246 |
2247 <pre> | 2247 <pre> |
2251 <p> | 2251 <p> |
2252 will iterate over all values of <code>···</code>. | 2252 will iterate over all values of <code>···</code>. |
2253 | 2253 |
2254 | 2254 |
2255 | 2255 |
2256 <h4 heading><a name="Luan.VERSION"><code>Luan.VERSION</code></a></h4> | 2256 <h4 heading><a name="Luan.VERSION" href="#Luan.VERSION"><code>Luan.VERSION</code></a></h4> |
2257 | 2257 |
2258 <p> | 2258 <p> |
2259 A global variable (not a function) that | 2259 A global variable (not a function) that |
2260 holds a string containing the current interpreter version. | 2260 holds a string containing the current interpreter version. |
2261 The current value of this variable is "<code><%=Luan.VERSION%></code>". | 2261 The current value of this variable is "<code><%=Luan.VERSION%></code>". |
2277 <p> | 2277 <p> |
2278 The package library provides basic | 2278 The package library provides basic |
2279 facilities for loading modules in Luan. | 2279 facilities for loading modules in Luan. |
2280 | 2280 |
2281 | 2281 |
2282 <h4 heading><a name="Package.load"><code>Package.load (mod_uri)</code></a></h4> | 2282 <h4 heading><a name="Package.load" href="#Package.load"><code>Package.load (mod_uri)</code></a></h4> |
2283 | 2283 |
2284 <p> | 2284 <p> |
2285 Loads the given module. | 2285 Loads the given module. |
2286 The function starts by looking into the <a href="#Package.loaded"><code>Package.loaded</code></a> table | 2286 The function starts by looking into the <a href="#Package.loaded"><code>Package.loaded</code></a> table |
2287 to determine whether <code>mod_uri</code> is already loaded. | 2287 to determine whether <code>mod_uri</code> is already loaded. |
2299 If a new value for the module successful loaded, then it is stored in <code>Package.loaded[mod_uri]</code>. The value is returned. | 2299 If a new value for the module successful loaded, then it is stored in <code>Package.loaded[mod_uri]</code>. The value is returned. |
2300 | 2300 |
2301 | 2301 |
2302 | 2302 |
2303 | 2303 |
2304 <h4 heading><a name="Package.loaded"><code>Package.loaded</code></a></h4> | 2304 <h4 heading><a name="Package.loaded" href="#Package.loaded"><code>Package.loaded</code></a></h4> |
2305 | 2305 |
2306 | 2306 |
2307 <p> | 2307 <p> |
2308 A table used by <a href="#Package.load"><code>Package.load</code></a> to control which | 2308 A table used by <a href="#Package.load"><code>Package.load</code></a> to control which |
2309 modules are already loaded. | 2309 modules are already loaded. |
2340 from the end of the string. | 2340 from the end of the string. |
2341 Thus, the last character is at position -1, and so on. | 2341 Thus, the last character is at position -1, and so on. |
2342 | 2342 |
2343 | 2343 |
2344 | 2344 |
2345 <h4 heading><a name="String.char"><code>String.char (···)</code></a></h4> | 2345 <h4 heading><a name="String.char" href="#String.char"><code>String.char (···)</code></a></h4> |
2346 | 2346 |
2347 <p> | 2347 <p> |
2348 Receives zero or more integers. | 2348 Receives zero or more integers. |
2349 Returns a string with length equal to the number of arguments, | 2349 Returns a string with length equal to the number of arguments, |
2350 in which each character has the internal numerical code equal | 2350 in which each character has the internal numerical code equal |
2351 to its corresponding argument. | 2351 to its corresponding argument. |
2352 | 2352 |
2353 | 2353 |
2354 <h4 heading><a name="String.concat"><code>String.concat (···)</code></a></h4> | 2354 <h4 heading><a name="String.concat" href="#String.concat"><code>String.concat (···)</code></a></h4> |
2355 | 2355 |
2356 <p> | 2356 <p> |
2357 Concatenates the <a href="#Luan.to_string"><code>to_string</code></a> value of all arguments. | 2357 Concatenates the <a href="#Luan.to_string"><code>to_string</code></a> value of all arguments. |
2358 | 2358 |
2359 | 2359 |
2360 | 2360 |
2361 <h4 heading><a name="String.encode"><code>String.encode (s)</code></a></h4> | 2361 <h4 heading><a name="String.encode" href="#String.encode"><code>String.encode (s)</code></a></h4> |
2362 | 2362 |
2363 <p> | 2363 <p> |
2364 Encodes argument <code>s</code> into a string that can be placed in quotes so as to return the original value of the string. | 2364 Encodes argument <code>s</code> into a string that can be placed in quotes so as to return the original value of the string. |
2365 | 2365 |
2366 | 2366 |
2367 | 2367 |
2368 | 2368 |
2369 <h4 heading><a name="String.find"><code>String.find (s, pattern [, init [, plain]])</code></a></h4> | 2369 <h4 heading><a name="String.find" href="#String.find"><code>String.find (s, pattern [, init [, plain]])</code></a></h4> |
2370 | 2370 |
2371 <p> | 2371 <p> |
2372 Looks for the first match of | 2372 Looks for the first match of |
2373 <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) in the string <code>s</code>. | 2373 <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) in the string <code>s</code>. |
2374 If it finds a match, then <code>find</code> returns the indices of <code>s</code> | 2374 If it finds a match, then <code>find</code> returns the indices of <code>s</code> |
2390 after the two indices. | 2390 after the two indices. |
2391 | 2391 |
2392 | 2392 |
2393 | 2393 |
2394 | 2394 |
2395 <h4 heading><a name="String.format"><code>String.format (formatstring, ···)</code></a></h4> | 2395 <h4 heading><a name="String.format" href="#String.format"><code>String.format (formatstring, ···)</code></a></h4> |
2396 | 2396 |
2397 | 2397 |
2398 <p> | 2398 <p> |
2399 Returns a formatted version of its variable number of arguments | 2399 Returns a formatted version of its variable number of arguments |
2400 following the description given in its first argument (which must be a string). | 2400 following the description given in its first argument (which must be a string). |
2403 <p> | 2403 <p> |
2404 Note that Java's <code>String.format</code> is too stupid to convert between ints and floats, so you must provide the right kind of number. | 2404 Note that Java's <code>String.format</code> is too stupid to convert between ints and floats, so you must provide the right kind of number. |
2405 | 2405 |
2406 | 2406 |
2407 | 2407 |
2408 <h4 heading><a name="String.gmatch"><code>String.gmatch (s, pattern)</code></a></h4> | 2408 <h4 heading><a name="String.gmatch" href="#String.gmatch"><code>String.gmatch (s, pattern)</code></a></h4> |
2409 | 2409 |
2410 <p> | 2410 <p> |
2411 Returns an iterator function that, | 2411 Returns an iterator function that, |
2412 each time it is called, | 2412 each time it is called, |
2413 returns the next captures from <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) | 2413 returns the next captures from <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) |
2444 For this function, a caret '<code>^</code>' at the start of a pattern does not | 2444 For this function, a caret '<code>^</code>' at the start of a pattern does not |
2445 work as an anchor, as this would prevent the iteration. | 2445 work as an anchor, as this would prevent the iteration. |
2446 | 2446 |
2447 | 2447 |
2448 | 2448 |
2449 <h4 heading><a name="String.gsub"><code>String.gsub (s, pattern, repl [, n])</code></a></h4> | 2449 <h4 heading><a name="String.gsub" href="#String.gsub"><code>String.gsub (s, pattern, repl [, n])</code></a></h4> |
2450 | 2450 |
2451 <p> | 2451 <p> |
2452 Returns a copy of <code>s</code> | 2452 Returns a copy of <code>s</code> |
2453 in which all (or the first <code>n</code>, if given) | 2453 in which all (or the first <code>n</code>, if given) |
2454 occurrences of the <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) have been | 2454 occurrences of the <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) have been |
2517 --> x="lua-5.3.tar.gz" | 2517 --> x="lua-5.3.tar.gz" |
2518 </pre> | 2518 </pre> |
2519 | 2519 |
2520 | 2520 |
2521 | 2521 |
2522 <h4 heading><a name="String.literal"><code>String.literal (s)</code></a></h4> | 2522 <h4 heading><a name="String.literal" href="#String.literal"><code>String.literal (s)</code></a></h4> |
2523 <p> | 2523 <p> |
2524 Returns a string which matches the literal string <code>s</code> in a regular expression. This function is simply the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#quote(java.lang.String)"><code>Pattern.quote</code></a>. | 2524 Returns a string which matches the literal string <code>s</code> in a regular expression. This function is simply the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#quote(java.lang.String)"><code>Pattern.quote</code></a>. |
2525 | 2525 |
2526 | 2526 |
2527 <h4 heading><a name="String.lower"><code>String.lower (s)</code></a></h4> | 2527 <h4 heading><a name="String.lower" href="#String.lower"><code>String.lower (s)</code></a></h4> |
2528 <p> | 2528 <p> |
2529 Receives a string and returns a copy of this string with all | 2529 Receives a string and returns a copy of this string with all |
2530 uppercase letters changed to lowercase. | 2530 uppercase letters changed to lowercase. |
2531 All other characters are left unchanged. | 2531 All other characters are left unchanged. |
2532 | 2532 |
2533 | 2533 |
2534 | 2534 |
2535 | 2535 |
2536 <h4 heading><a name="String.match"><code>String.match (s, pattern [, init])</code></a></h4> | 2536 <h4 heading><a name="String.match" href="#String.match"><code>String.match (s, pattern [, init])</code></a></h4> |
2537 | 2537 |
2538 <p> | 2538 <p> |
2539 Looks for the first <em>match</em> of | 2539 Looks for the first <em>match</em> of |
2540 <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) in the string <code>s</code>. | 2540 <code>pattern</code> (see <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a>) in the string <code>s</code>. |
2541 If it finds one, then <code>match</code> returns | 2541 If it finds one, then <code>match</code> returns |
2546 A third, optional numerical argument <code>init</code> specifies | 2546 A third, optional numerical argument <code>init</code> specifies |
2547 where to start the search; | 2547 where to start the search; |
2548 its default value is 1 and can be negative. | 2548 its default value is 1 and can be negative. |
2549 | 2549 |
2550 | 2550 |
2551 <h4 heading><a name="String.matches"><code>String.matches (s, pattern)</code></a></h4> | 2551 <h4 heading><a name="String.matches" href="#String.matches"><code>String.matches (s, pattern)</code></a></h4> |
2552 <p> | 2552 <p> |
2553 Returns a boolean indicating whether the <code>pattern</code> can be found in string <code>s</code>. | 2553 Returns a boolean indicating whether the <code>pattern</code> can be found in string <code>s</code>. |
2554 This function is equivalent to | 2554 This function is equivalent to |
2555 | 2555 |
2556 <pre> | 2556 <pre> |
2557 return String.match(s,pattern) ~= nil | 2557 return String.match(s,pattern) ~= nil |
2558 </pre> | 2558 </pre> |
2559 | 2559 |
2560 | 2560 |
2561 <h4 heading><a name="String.rep"><code>String.rep (s, n [, sep])</code></a></h4> | 2561 <h4 heading><a name="String.rep" href="#String.rep"><code>String.rep (s, n [, sep])</code></a></h4> |
2562 <p> | 2562 <p> |
2563 Returns a string that is the concatenation of <code>n</code> copies of | 2563 Returns a string that is the concatenation of <code>n</code> copies of |
2564 the string <code>s</code> separated by the string <code>sep</code>. | 2564 the string <code>s</code> separated by the string <code>sep</code>. |
2565 The default value for <code>sep</code> is the empty string | 2565 The default value for <code>sep</code> is the empty string |
2566 (that is, no separator). | 2566 (that is, no separator). |
2567 Returns the empty string if <code>n</code> is not positive. | 2567 Returns the empty string if <code>n</code> is not positive. |
2568 | 2568 |
2569 | 2569 |
2570 | 2570 |
2571 | 2571 |
2572 <h4 heading><a name="String.reverse"><code>String.reverse (s)</code></a></h4> | 2572 <h4 heading><a name="String.reverse" href="#String.reverse"><code>String.reverse (s)</code></a></h4> |
2573 <p> | 2573 <p> |
2574 Returns a string that is the string <code>s</code> reversed. | 2574 Returns a string that is the string <code>s</code> reversed. |
2575 | 2575 |
2576 | 2576 |
2577 | 2577 |
2578 | 2578 |
2579 <h4 heading><a name="String.sub"><code>String.sub (s, i [, j])</code></a></h4> | 2579 <h4 heading><a name="String.sub" href="#String.sub"><code>String.sub (s, i [, j])</code></a></h4> |
2580 | 2580 |
2581 <p> | 2581 <p> |
2582 Returns the substring of <code>s</code> that | 2582 Returns the substring of <code>s</code> that |
2583 starts at <code>i</code> and continues until <code>j</code>; | 2583 starts at <code>i</code> and continues until <code>j</code>; |
2584 <code>i</code> and <code>j</code> can be negative. | 2584 <code>i</code> and <code>j</code> can be negative. |
2601 <code>i</code> is greater than <code>j</code>, | 2601 <code>i</code> is greater than <code>j</code>, |
2602 the function returns the empty string. | 2602 the function returns the empty string. |
2603 | 2603 |
2604 | 2604 |
2605 | 2605 |
2606 <h4 heading><a name="String.to_binary"><code>String.to_binary (s)</code></a></h4> | 2606 <h4 heading><a name="String.to_binary" href="#String.to_binary"><code>String.to_binary (s)</code></a></h4> |
2607 | 2607 |
2608 <p> | 2608 <p> |
2609 Converts a string to a binary by calling the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes()"><code>String.getBytes</code></a>. | 2609 Converts a string to a binary by calling the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes()"><code>String.getBytes</code></a>. |
2610 | 2610 |
2611 | 2611 |
2612 | 2612 |
2613 <h4 heading><a name="String.to_number"><code>String.to_number (s [, base])</code></a></h4> | 2613 <h4 heading><a name="String.to_number" href="#String.to_number"><code>String.to_number (s [, base])</code></a></h4> |
2614 | 2614 |
2615 <p> | 2615 <p> |
2616 When called with no <code>base</code>, | 2616 When called with no <code>base</code>, |
2617 <code>to_number</code> tries to convert its argument to a number. | 2617 <code>to_number</code> tries to convert its argument to a number. |
2618 If the argument is | 2618 If the argument is |
2633 If the string <code>s</code> is not a valid numeral in the given base, | 2633 If the string <code>s</code> is not a valid numeral in the given base, |
2634 the function returns <b>nil</b>. | 2634 the function returns <b>nil</b>. |
2635 | 2635 |
2636 | 2636 |
2637 | 2637 |
2638 <h4 heading><a name="String.trim"><code>String.trim (s)</code></a></h4> | 2638 <h4 heading><a name="String.trim" href="#String.trim"><code>String.trim (s)</code></a></h4> |
2639 | 2639 |
2640 <p> | 2640 <p> |
2641 Removes the leading and trailing whitespace by calling the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#trim()"><code>String.trim</code></a>. | 2641 Removes the leading and trailing whitespace by calling the Java method <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#trim()"><code>String.trim</code></a>. |
2642 | 2642 |
2643 | 2643 |
2644 | 2644 |
2645 | 2645 |
2646 <h4 heading><a name="String.unicode"><code>String.unicode (s [, i [, j]])</code></a></h4> | 2646 <h4 heading><a name="String.unicode" href="#String.unicode"><code>String.unicode (s [, i [, j]])</code></a></h4> |
2647 | 2647 |
2648 <p> | 2648 <p> |
2649 Returns the internal numerical codes of the characters <code>s[i]</code>, | 2649 Returns the internal numerical codes of the characters <code>s[i]</code>, |
2650 <code>s[i+1]</code>, ..., <code>s[j]</code>. | 2650 <code>s[i+1]</code>, ..., <code>s[j]</code>. |
2651 The default value for <code>i</code> is 1; | 2651 The default value for <code>i</code> is 1; |
2655 | 2655 |
2656 | 2656 |
2657 | 2657 |
2658 | 2658 |
2659 | 2659 |
2660 <h4 heading><a name="String.upper"><code>String.upper (s)</code></a></h4> | 2660 <h4 heading><a name="String.upper" href="#String.upper"><code>String.upper (s)</code></a></h4> |
2661 <p> | 2661 <p> |
2662 Receives a string and returns a copy of this string with all | 2662 Receives a string and returns a copy of this string with all |
2663 lowercase letters changed to uppercase. | 2663 lowercase letters changed to uppercase. |
2664 All other characters are left unchanged. | 2664 All other characters are left unchanged. |
2665 The definition of what a lowercase letter is depends on the current locale. | 2665 The definition of what a lowercase letter is depends on the current locale. |
2676 <pre> | 2676 <pre> |
2677 local Binary = require "luan:Binary" | 2677 local Binary = require "luan:Binary" |
2678 </pre> | 2678 </pre> |
2679 | 2679 |
2680 | 2680 |
2681 <h4 heading><a name="Binary.binary"><code>Binary.binary (···)</code></a></h4> | 2681 <h4 heading><a name="Binary.binary" href="#Binary.binary"><code>Binary.binary (···)</code></a></h4> |
2682 | 2682 |
2683 <p> | 2683 <p> |
2684 Receives zero or more bytes (as integers). | 2684 Receives zero or more bytes (as integers). |
2685 Returns a binary with length equal to the number of arguments, | 2685 Returns a binary with length equal to the number of arguments, |
2686 in which each byte has the internal numerical code equal | 2686 in which each byte has the internal numerical code equal |
2687 to its corresponding argument. | 2687 to its corresponding argument. |
2688 | 2688 |
2689 | 2689 |
2690 <h4 heading><a name="Binary.byte"><code>Binary.byte (b [, i [, j]])</code></a></h4> | 2690 <h4 heading><a name="Binary.byte" href="#Binary.byte"><code>Binary.byte (b [, i [, j]])</code></a></h4> |
2691 | 2691 |
2692 <p> | 2692 <p> |
2693 Returns the internal numerical codes of the bytes <code>b[i]</code>, | 2693 Returns the internal numerical codes of the bytes <code>b[i]</code>, |
2694 <code>b[i+1]</code>, ..., <code>b[j]</code>. | 2694 <code>b[i+1]</code>, ..., <code>b[j]</code>. |
2695 The default value for <code>i</code> is 1; | 2695 The default value for <code>i</code> is 1; |
2696 the default value for <code>j</code> is <code>i</code>. | 2696 the default value for <code>j</code> is <code>i</code>. |
2697 These indices are corrected | 2697 These indices are corrected |
2698 following the same rules of function <a href="#String.sub"><code>String.sub</code></a>. | 2698 following the same rules of function <a href="#String.sub"><code>String.sub</code></a>. |
2699 | 2699 |
2700 | 2700 |
2701 <h4 heading><a name="Binary.to_string"><code>Binary.to_string (b)</code></a></h4> | 2701 <h4 heading><a name="Binary.to_string" href="#Binary.to_string"><code>Binary.to_string (b)</code></a></h4> |
2702 <p> | 2702 <p> |
2703 Converts the binary <code>b</code> to a string using the Java <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#String(byte[])">String constructor</a>. | 2703 Converts the binary <code>b</code> to a string using the Java <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#String(byte[])">String constructor</a>. |
2704 | 2704 |
2705 | 2705 |
2706 | 2706 |
2718 This library provides generic functions for table manipulation. | 2718 This library provides generic functions for table manipulation. |
2719 It provides all its functions inside the table <code>Table</code>. | 2719 It provides all its functions inside the table <code>Table</code>. |
2720 | 2720 |
2721 | 2721 |
2722 | 2722 |
2723 <h4 heading><a name="Table.clear"><code>Table.clear (tbl)</code></a></h4> | 2723 <h4 heading><a name="Table.clear" href="#Table.clear"><code>Table.clear (tbl)</code></a></h4> |
2724 | 2724 |
2725 <p> | 2725 <p> |
2726 Clears the table. | 2726 Clears the table. |
2727 | 2727 |
2728 | 2728 |
2729 <h4 heading><a name="Table.concat"><code>Table.concat (list [, sep [, i [, j]]])</code></a></h4> | 2729 <h4 heading><a name="Table.concat" href="#Table.concat"><code>Table.concat (list [, sep [, i [, j]]])</code></a></h4> |
2730 | 2730 |
2731 <p> | 2731 <p> |
2732 Given a list, | 2732 Given a list, |
2733 returns the string <code>list[i]..sep..list[i+1] ··· sep..list[j]</code>. | 2733 returns the string <code>list[i]..sep..list[i+1] ··· sep..list[j]</code>. |
2734 The default value for <code>sep</code> is the empty string, | 2734 The default value for <code>sep</code> is the empty string, |
2735 the default for <code>i</code> is 1, | 2735 the default for <code>i</code> is 1, |
2736 and the default for <code>j</code> is <code>#list</code>. | 2736 and the default for <code>j</code> is <code>#list</code>. |
2737 If <code>i</code> is greater than <code>j</code>, returns the empty string. | 2737 If <code>i</code> is greater than <code>j</code>, returns the empty string. |
2738 | 2738 |
2739 | 2739 |
2740 <h4 heading><a name="Table.copy"><code>Table.copy (tbl [, i [, j]])</code></a></h4> | 2740 <h4 heading><a name="Table.copy" href="#Table.copy"><code>Table.copy (tbl [, i [, j]])</code></a></h4> |
2741 | 2741 |
2742 <p> | 2742 <p> |
2743 If <code>i</code> is <code>nil</code>, returns a shallow copy of <code>tbl</code>. | 2743 If <code>i</code> is <code>nil</code>, returns a shallow copy of <code>tbl</code>. |
2744 Otherwise returns a new table which is a list of the elements <code>tbl[i] ··· tbl[j]</code>. | 2744 Otherwise returns a new table which is a list of the elements <code>tbl[i] ··· tbl[j]</code>. |
2745 By default, <code>j</code> is <code>#tbl</code>. | 2745 By default, <code>j</code> is <code>#tbl</code>. |
2746 | 2746 |
2747 | 2747 |
2748 | 2748 |
2749 <h4 heading><a name="Table.insert"><code>Table.insert (list, pos, value)</code></a></h4> | 2749 <h4 heading><a name="Table.insert" href="#Table.insert"><code>Table.insert (list, pos, value)</code></a></h4> |
2750 | 2750 |
2751 <p> | 2751 <p> |
2752 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>, | 2752 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>, |
2753 shifting up the elements | 2753 shifting up the elements |
2754 <code>list[pos], list[pos+1], ···, list[#list]</code>. | 2754 <code>list[pos], list[pos+1], ···, list[#list]</code>. |
2755 | 2755 |
2756 | 2756 |
2757 | 2757 |
2758 <h4 heading><a name="Table.pack"><code>Table.pack (···)</code></a></h4> | 2758 <h4 heading><a name="Table.pack" href="#Table.pack"><code>Table.pack (···)</code></a></h4> |
2759 | 2759 |
2760 <p> | 2760 <p> |
2761 Returns a new table with all parameters stored into keys 1, 2, etc. | 2761 Returns a new table with all parameters stored into keys 1, 2, etc. |
2762 and with a field "<code>n</code>" with the total number of parameters. | 2762 and with a field "<code>n</code>" with the total number of parameters. |
2763 Note that the resulting table may not be a sequence. | 2763 Note that the resulting table may not be a sequence. |
2764 | 2764 |
2765 | 2765 |
2766 | 2766 |
2767 | 2767 |
2768 <h4 heading><a name="Table.remove"><code>Table.remove (list, pos)</code></a></h4> | 2768 <h4 heading><a name="Table.remove" href="#Table.remove"><code>Table.remove (list, pos)</code></a></h4> |
2769 | 2769 |
2770 | 2770 |
2771 <p> | 2771 <p> |
2772 Removes from <code>list</code> the element at position <code>pos</code>, | 2772 Removes from <code>list</code> the element at position <code>pos</code>, |
2773 returning the value of the removed element. | 2773 returning the value of the removed element. |
2780 in those cases, the function erases the element <code>list[pos]</code>. | 2780 in those cases, the function erases the element <code>list[pos]</code>. |
2781 | 2781 |
2782 | 2782 |
2783 | 2783 |
2784 | 2784 |
2785 <h4 heading><a name="Table.sort"><code>Table.sort (list [, comp])</code></a></h4> | 2785 <h4 heading><a name="Table.sort" href="#Table.sort"><code>Table.sort (list [, comp])</code></a></h4> |
2786 | 2786 |
2787 <p> | 2787 <p> |
2788 Sorts list elements in a given order, <em>in-place</em>, | 2788 Sorts list elements in a given order, <em>in-place</em>, |
2789 from <code>list[1]</code> to <code>list[#list]</code>. | 2789 from <code>list[1]</code> to <code>list[#list]</code>. |
2790 If <code>comp</code> is given, | 2790 If <code>comp</code> is given, |
2800 that is, elements considered equal by the given order | 2800 that is, elements considered equal by the given order |
2801 may have their relative positions changed by the sort. | 2801 may have their relative positions changed by the sort. |
2802 | 2802 |
2803 | 2803 |
2804 | 2804 |
2805 <h4 heading><a name="Table.unpack"><code>Table.unpack (list [, i [, j]])</code></a></h4> | 2805 <h4 heading><a name="Table.unpack" href="#Table.unpack"><code>Table.unpack (list [, i [, j]])</code></a></h4> |
2806 | 2806 |
2807 <p> | 2807 <p> |
2808 Returns the elements from the given list. | 2808 Returns the elements from the given list. |
2809 This function is equivalent to | 2809 This function is equivalent to |
2810 | 2810 |
2826 <pre> | 2826 <pre> |
2827 local Number = require "luan:Number" | 2827 local Number = require "luan:Number" |
2828 </pre> | 2828 </pre> |
2829 | 2829 |
2830 | 2830 |
2831 <h4 heading><a name="Number.double"><code>Number.double (x)</code></a></h4> | 2831 <h4 heading><a name="Number.double" href="#Number.double"><code>Number.double (x)</code></a></h4> |
2832 <p> | 2832 <p> |
2833 Returns <code>x</code> as a double. | 2833 Returns <code>x</code> as a double. |
2834 | 2834 |
2835 | 2835 |
2836 <h4 heading><a name="Number.integer"><code>Number.integer (x)</code></a></h4> | 2836 <h4 heading><a name="Number.integer" href="#Number.integer"><code>Number.integer (x)</code></a></h4> |
2837 <p> | 2837 <p> |
2838 If the value <code>x</code> is convertible to an integer, | 2838 If the value <code>x</code> is convertible to an integer, |
2839 returns that integer. | 2839 returns that integer. |
2840 Otherwise throws an error. | 2840 Otherwise throws an error. |
2841 | 2841 |
2842 | 2842 |
2843 <h4 heading><a name="Number.long"><code>Number.long (x)</code></a></h4> | 2843 <h4 heading><a name="Number.long" href="#Number.long"><code>Number.long (x)</code></a></h4> |
2844 <p> | 2844 <p> |
2845 If the value <code>x</code> is convertible to an long, | 2845 If the value <code>x</code> is convertible to an long, |
2846 returns that long. | 2846 returns that long. |
2847 Otherwise throws an error. | 2847 Otherwise throws an error. |
2848 | 2848 |
2849 | 2849 |
2850 <h4 heading><a name="Number.long_to_string"><code>Number.long_to_string (i, radix)</code></a></h4> | 2850 <h4 heading><a name="Number.long_to_string" href="#Number.long_to_string"><code>Number.long_to_string (i, radix)</code></a></h4> |
2851 <p> | 2851 <p> |
2852 Converts long value <code>i</code> to a string by calling <code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#toString(long,%20int)">Long.toString</a></code>. | 2852 Converts long value <code>i</code> to a string by calling <code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#toString(long,%20int)">Long.toString</a></code>. |
2853 | 2853 |
2854 | 2854 |
2855 <h4 heading><a name="Number.type"><code>Number.type (x)</code></a></h4> | 2855 <h4 heading><a name="Number.type" href="#Number.type"><code>Number.type (x)</code></a></h4> |
2856 <p> | 2856 <p> |
2857 Returns a string for the numeric type of <code>x</code>. Possible return values include "<code>integer</code>", "<code>long</code>", "<code>double</code>", and "<code>float</code>". | 2857 Returns a string for the numeric type of <code>x</code>. Possible return values include "<code>integer</code>", "<code>long</code>", "<code>double</code>", and "<code>float</code>". |
2858 | 2858 |
2859 | 2859 |
2860 | 2860 |
2871 <p> | 2871 <p> |
2872 This library provides basic mathematical functions. | 2872 This library provides basic mathematical functions. |
2873 It provides all its functions and constants inside the table <code>Math</code>. | 2873 It provides all its functions and constants inside the table <code>Math</code>. |
2874 | 2874 |
2875 | 2875 |
2876 <h4 heading><a name="Math.abs"><code>Math.abs (x)</code></a></h4> | 2876 <h4 heading><a name="Math.abs" href="#Math.abs"><code>Math.abs (x)</code></a></h4> |
2877 | 2877 |
2878 <p> | 2878 <p> |
2879 Returns the absolute value of <code>x</code>. | 2879 Returns the absolute value of <code>x</code>. |
2880 | 2880 |
2881 | 2881 |
2882 | 2882 |
2883 <h4 heading><a name="Math.acos"><code>Math.acos (x)</code></a></h4> | 2883 <h4 heading><a name="Math.acos" href="#Math.acos"><code>Math.acos (x)</code></a></h4> |
2884 | 2884 |
2885 <p> | 2885 <p> |
2886 Returns the arc cosine of <code>x</code> (in radians). | 2886 Returns the arc cosine of <code>x</code> (in radians). |
2887 | 2887 |
2888 | 2888 |
2889 | 2889 |
2890 | 2890 |
2891 <h4 heading><a name="Math.asin"><code>Math.asin (x)</code></a></h4> | 2891 <h4 heading><a name="Math.asin" href="#Math.asin"><code>Math.asin (x)</code></a></h4> |
2892 | 2892 |
2893 <p> | 2893 <p> |
2894 Returns the arc sine of <code>x</code> (in radians). | 2894 Returns the arc sine of <code>x</code> (in radians). |
2895 | 2895 |
2896 | 2896 |
2897 | 2897 |
2898 | 2898 |
2899 <h4 heading><a name="Math.atan"><code>Math.atan (y, x)</code></a></h4> | 2899 <h4 heading><a name="Math.atan" href="#Math.atan"><code>Math.atan (y, x)</code></a></h4> |
2900 | 2900 |
2901 <p> | 2901 <p> |
2902 Returns the arc tangent of <code>y/x</code> (in radians), | 2902 Returns the arc tangent of <code>y/x</code> (in radians), |
2903 but uses the signs of both parameters to find the | 2903 but uses the signs of both parameters to find the |
2904 quadrant of the result. | 2904 quadrant of the result. |
2905 (It also handles correctly the case of <code>x</code> being zero.) | 2905 (It also handles correctly the case of <code>x</code> being zero.) |
2906 | 2906 |
2907 | 2907 |
2908 | 2908 |
2909 | 2909 |
2910 <h4 heading><a name="Math.ceil"><code>Math.ceil (x)</code></a></h4> | 2910 <h4 heading><a name="Math.ceil" href="#Math.ceil"><code>Math.ceil (x)</code></a></h4> |
2911 | 2911 |
2912 <p> | 2912 <p> |
2913 Returns the smallest integral value larger than or equal to <code>x</code>. | 2913 Returns the smallest integral value larger than or equal to <code>x</code>. |
2914 | 2914 |
2915 | 2915 |
2916 | 2916 |
2917 | 2917 |
2918 <h4 heading><a name="Math.cos"><code>Math.cos (x)</code></a></h4> | 2918 <h4 heading><a name="Math.cos" href="#Math.cos"><code>Math.cos (x)</code></a></h4> |
2919 | 2919 |
2920 <p> | 2920 <p> |
2921 Returns the cosine of <code>x</code> (assumed to be in radians). | 2921 Returns the cosine of <code>x</code> (assumed to be in radians). |
2922 | 2922 |
2923 | 2923 |
2924 | 2924 |
2925 | 2925 |
2926 <h4 heading><a name="Math.deg"><code>Math.deg (x)</code></a></h4> | 2926 <h4 heading><a name="Math.deg" href="#Math.deg"><code>Math.deg (x)</code></a></h4> |
2927 | 2927 |
2928 <p> | 2928 <p> |
2929 Converts the angle <code>x</code> from radians to degrees. | 2929 Converts the angle <code>x</code> from radians to degrees. |
2930 | 2930 |
2931 | 2931 |
2932 | 2932 |
2933 | 2933 |
2934 <h4 heading><a name="Math.exp"><code>Math.exp (x)</code></a></h4> | 2934 <h4 heading><a name="Math.exp" href="#Math.exp"><code>Math.exp (x)</code></a></h4> |
2935 | 2935 |
2936 <p> | 2936 <p> |
2937 Returns the value <em>e<sup>x</sup></em> | 2937 Returns the value <em>e<sup>x</sup></em> |
2938 (where <code>e</code> is the base of natural logarithms). | 2938 (where <code>e</code> is the base of natural logarithms). |
2939 | 2939 |
2940 | 2940 |
2941 | 2941 |
2942 | 2942 |
2943 <h4 heading><a name="Math.floor"><code>Math.floor (x)</code></a></h4> | 2943 <h4 heading><a name="Math.floor" href="#Math.floor"><code>Math.floor (x)</code></a></h4> |
2944 | 2944 |
2945 <p> | 2945 <p> |
2946 Returns the largest integral value smaller than or equal to <code>x</code>. | 2946 Returns the largest integral value smaller than or equal to <code>x</code>. |
2947 | 2947 |
2948 | 2948 |
2949 | 2949 |
2950 | 2950 |
2951 <h4 heading><a name="Math.fmod"><code>Math.fmod (x, y)</code></a></h4> | 2951 <h4 heading><a name="Math.fmod" href="#Math.fmod"><code>Math.fmod (x, y)</code></a></h4> |
2952 | 2952 |
2953 <p> | 2953 <p> |
2954 Returns the remainder of the division of <code>x</code> by <code>y</code> | 2954 Returns the remainder of the division of <code>x</code> by <code>y</code> |
2955 that rounds the quotient towards zero. | 2955 that rounds the quotient towards zero. |
2956 | 2956 |
2957 | 2957 |
2958 | 2958 |
2959 | 2959 |
2960 <h4 heading><a name="Math.huge"><code>Math.huge</code></a></h4> | 2960 <h4 heading><a name="Math.huge" href="#Math.huge"><code>Math.huge</code></a></h4> |
2961 | 2961 |
2962 <p> | 2962 <p> |
2963 A value larger than any other numerical value. | 2963 A value larger than any other numerical value. |
2964 | 2964 |
2965 | 2965 |
2966 | 2966 |
2967 | 2967 |
2968 <h4 heading><a name="Math.log"><code>Math.log (x [, base])</code></a></h4> | 2968 <h4 heading><a name="Math.log" href="#Math.log"><code>Math.log (x [, base])</code></a></h4> |
2969 | 2969 |
2970 <p> | 2970 <p> |
2971 Returns the logarithm of <code>x</code> in the given base. | 2971 Returns the logarithm of <code>x</code> in the given base. |
2972 The default for <code>base</code> is <em>e</em> | 2972 The default for <code>base</code> is <em>e</em> |
2973 (so that the function returns the natural logarithm of <code>x</code>). | 2973 (so that the function returns the natural logarithm of <code>x</code>). |
2974 | 2974 |
2975 | 2975 |
2976 | 2976 |
2977 | 2977 |
2978 <h4 heading><a name="Math.max"><code>Math.max (x, ···)</code></a></h4> | 2978 <h4 heading><a name="Math.max" href="#Math.max"><code>Math.max (x, ···)</code></a></h4> |
2979 | 2979 |
2980 <p> | 2980 <p> |
2981 Returns the argument with the maximum value, | 2981 Returns the argument with the maximum value, |
2982 according to the Lua operator <code><</code>. | 2982 according to the Lua operator <code><</code>. |
2983 | 2983 |
2984 | 2984 |
2985 | 2985 |
2986 | 2986 |
2987 <h4 heading><a name="Math.max_integer"><code>Math.max_integer</code></a></h4> | 2987 <h4 heading><a name="Math.max_integer" href="#Math.max_integer"><code>Math.max_integer</code></a></h4> |
2988 <p> | 2988 <p> |
2989 An integer with the maximum value for an integer. | 2989 An integer with the maximum value for an integer. |
2990 | 2990 |
2991 | 2991 |
2992 | 2992 |
2993 | 2993 |
2994 <h4 heading><a name="Math.min"><code>Math.min (x, ···)</code></a></h4> | 2994 <h4 heading><a name="Math.min" href="#Math.min"><code>Math.min (x, ···)</code></a></h4> |
2995 | 2995 |
2996 <p> | 2996 <p> |
2997 Returns the argument with the minimum value, | 2997 Returns the argument with the minimum value, |
2998 according to the Lua operator <code><</code>. | 2998 according to the Lua operator <code><</code>. |
2999 | 2999 |
3000 | 3000 |
3001 | 3001 |
3002 | 3002 |
3003 <h4 heading><a name="Math.min_integer"><code>Math.min_integer</code></a></h4> | 3003 <h4 heading><a name="Math.min_integer" href="#Math.min_integer"><code>Math.min_integer</code></a></h4> |
3004 <p> | 3004 <p> |
3005 An integer with the minimum value for an integer. | 3005 An integer with the minimum value for an integer. |
3006 | 3006 |
3007 | 3007 |
3008 | 3008 |
3009 | 3009 |
3010 <h4 heading><a name="Math.modf"><code>Math.modf (x)</code></a></h4> | 3010 <h4 heading><a name="Math.modf" href="#Math.modf"><code>Math.modf (x)</code></a></h4> |
3011 | 3011 |
3012 <p> | 3012 <p> |
3013 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>. | 3013 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>. |
3014 | 3014 |
3015 | 3015 |
3016 | 3016 |
3017 | 3017 |
3018 <h4 heading><a name="Math.pi"><code>Math.pi</code></a></h4> | 3018 <h4 heading><a name="Math.pi" href="#Math.pi"><code>Math.pi</code></a></h4> |
3019 | 3019 |
3020 <p> | 3020 <p> |
3021 The value of <em>π</em>. | 3021 The value of <em>π</em>. |
3022 | 3022 |
3023 | 3023 |
3024 | 3024 |
3025 | 3025 |
3026 <h4 heading><a name="Math.rad"><code>Math.rad (x)</code></a></h4> | 3026 <h4 heading><a name="Math.rad" href="#Math.rad"><code>Math.rad (x)</code></a></h4> |
3027 | 3027 |
3028 <p> | 3028 <p> |
3029 Converts the angle <code>x</code> from degrees to radians. | 3029 Converts the angle <code>x</code> from degrees to radians. |
3030 | 3030 |
3031 | 3031 |
3032 | 3032 |
3033 | 3033 |
3034 <h4 heading><a name="Math.random"><code>Math.random ([m [, n])</code></a></h4> | 3034 <h4 heading><a name="Math.random" href="#Math.random"><code>Math.random ([m [, n])</code></a></h4> |
3035 | 3035 |
3036 | 3036 |
3037 <p> | 3037 <p> |
3038 When called without arguments, | 3038 When called without arguments, |
3039 returns a pseudo-random float with uniform distribution | 3039 returns a pseudo-random float with uniform distribution |
3051 No guarantees can be given for its statistical properties. | 3051 No guarantees can be given for its statistical properties. |
3052 | 3052 |
3053 | 3053 |
3054 | 3054 |
3055 | 3055 |
3056 <h4 heading><a name="Math.sin"><code>Math.sin (x)</code></a></h4> | 3056 <h4 heading><a name="Math.sin" href="#Math.sin"><code>Math.sin (x)</code></a></h4> |
3057 | 3057 |
3058 <p> | 3058 <p> |
3059 Returns the sine of <code>x</code> (assumed to be in radians). | 3059 Returns the sine of <code>x</code> (assumed to be in radians). |
3060 | 3060 |
3061 | 3061 |
3062 | 3062 |
3063 | 3063 |
3064 <h4 heading><a name="Math.sqrt"><code>Math.sqrt (x)</code></a></h4> | 3064 <h4 heading><a name="Math.sqrt" href="#Math.sqrt"><code>Math.sqrt (x)</code></a></h4> |
3065 | 3065 |
3066 <p> | 3066 <p> |
3067 Returns the square root of <code>x</code>. | 3067 Returns the square root of <code>x</code>. |
3068 (You can also use the expression <code>x^0.5</code> to compute this value.) | 3068 (You can also use the expression <code>x^0.5</code> to compute this value.) |
3069 | 3069 |
3070 | 3070 |
3071 | 3071 |
3072 | 3072 |
3073 <h4 heading><a name="Math.tan"><code>Math.tan (x)</code></a></h4> | 3073 <h4 heading><a name="Math.tan" href="#Math.tan"><code>Math.tan (x)</code></a></h4> |
3074 | 3074 |
3075 <p> | 3075 <p> |
3076 Returns the tangent of <code>x</code> (assumed to be in radians). | 3076 Returns the tangent of <code>x</code> (assumed to be in radians). |
3077 | 3077 |
3078 | 3078 |