2016-01-16 22:15:15 +01:00

780 lines
18 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>utils</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>utils</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/stringutil.html">stringutil</a></li>
<li><a href="../modules/random.html">random</a></li>
<li><a href="../modules/noisemanager.html">noisemanager</a></li>
<li><a href="../modules/nodeutil.html">nodeutil</a></li>
<li><a href="../modules/posutil.html">posutil</a></li>
<li><a href="../modules/objectrefutil.html">objectrefutil</a></li>
<li><a href="../modules/nodeboxutil.html">nodeboxutil</a></li>
<li><a href="../modules/mapmanipulator.html">mapmanipulator</a></li>
<li><a href="../modules/fisheryates.html">fisheryates</a></li>
<li><a href="../modules/textureutil.html">textureutil</a></li>
<li><a href="../modules/blockutil.html">blockutil</a></li>
<li><a href="../modules/tango.html">tango</a></li>
<li><a href="../modules/arraymanipulator.html">arraymanipulator</a></li>
<li><a href="../modules/inventoryutil.html">inventoryutil</a></li>
<li><a href="../modules/entityutil.html">entityutil</a></li>
<li><a href="../modules/scheduler.html">scheduler</a></li>
<li><a href="../modules/blockedcache.html">blockedcache</a></li>
<li><a href="../modules/mathutil.html">mathutil</a></li>
<li><a href="../modules/log.html">log</a></li>
<li><a href="../modules/arrayutil.html">arrayutil</a></li>
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
<li><a href="../modules/settings.html">settings</a></li>
<li><a href="../modules/pathutil.html">pathutil</a></li>
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
<li><a href="../modules/interpolate.html">interpolate</a></li>
<li><a href="../modules/transform.html">transform</a></li>
<li><a href="../modules/numberutil.html">numberutil</a></li>
<li><a href="../modules/test.html">test</a></li>
<li><a href="../modules/facedirutil.html">facedirutil</a></li>
<li><a href="../modules/constants.html">constants</a></li>
<li><a href="../modules/minetestex.html">minetestex</a></li>
<li><strong>list</strong></li>
<li><a href="../modules/stopwatch.html">stopwatch</a></li>
<li><a href="../modules/itemutil.html">itemutil</a></li>
<li><a href="../modules/color.html">color</a></li>
<li><a href="../modules/tableutil.html">tableutil</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>list</code></h1>
<p>A simple list that keeps the order in which the items are added to it.</p>
<p>
<p> It is a thin wrapper around a simple, number indexed table providing
various convenience methods.</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#ACCEPT_NON_NIL">ACCEPT_NON_NIL (value)</a></td>
<td class="summary">An accept function that only accepts non nil values.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#ACCEPT_NON_EMPTY_STRING">ACCEPT_NON_EMPTY_STRING (value)</a></td>
<td class="summary">An accept function that only accepts non empty string values.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:new">List:new (...)</a></td>
<td class="summary">Creates a new instance of List.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:add">List:add (...)</a></td>
<td class="summary">Adds the given items to the list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:add_list">List:add_list (...)</a></td>
<td class="summary">Adds the given List to the list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:clear">List:clear ()</a></td>
<td class="summary">Clears all entries from the list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:contains">List:contains (item)</a></td>
<td class="summary">Checks if this list contains the given item.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:cull_duplicates">List:cull_duplicates (comparator)</a></td>
<td class="summary">Culls/removes all duplicates from this list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:foreach">List:foreach (action)</a></td>
<td class="summary">Iterates over all items in the list and invokes the given action on them.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:get">List:get (index)</a></td>
<td class="summary">Gets the item at the given index.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:get_first">List:get_first (accept)</a></td>
<td class="summary">Gets the first value in this List that is accepted by the given function.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:get_last">List:get_last (accept)</a></td>
<td class="summary">Gets the last value in this List that is accepted by the given function.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:index">List:index (item, equals)</a></td>
<td class="summary">Returns the index of the given item.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:invoke">List:invoke (...)</a></td>
<td class="summary">If the List contains functions, this invokes all items with the given
parameters.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:is_empty">List:is_empty ()</a></td>
<td class="summary">Gets if this List is empty.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:matching">List:matching (condition)</a></td>
<td class="summary">Returns a List with all items that match the given condition.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:remove">List:remove (...)</a></td>
<td class="summary">Removes the given values from the list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:remove_index">List:remove_index (...)</a></td>
<td class="summary">Removes the given index from the list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:return_first">List:return_first (accept, ...)</a></td>
<td class="summary">Invokes the contained functions and returns the first value that is accepted
by the given function.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:return_last">List:return_last (accept, ...)</a></td>
<td class="summary">Invokes the contained functions and returns the last value that is accepted
by the given function.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:size">List:size ()</a></td>
<td class="summary">Gets the size of the list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:sort">List:sort (comparator)</a></td>
<td class="summary">Sorts this List.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:sub_list">List:sub_list (from, count)</a></td>
<td class="summary">Gets a sub list starting from the given index and the given number of items.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#List:to_table">List:to_table ()</a></td>
<td class="summary">Turns this list into a table, the return table will be a one indexed array,
and can freely be modified as it is not the table used by this instance.</td>
</tr>
</table>
<br/>
<br/>
<h2><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "ACCEPT_NON_NIL"></a>
<strong>ACCEPT_NON_NIL (value)</strong>
</dt>
<dd>
An accept function that only accepts non nil values.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
The value that is checked.
</li>
</ul>
<h3>Returns:</h3>
<ol>
true if the given value is not nil.
</ol>
</dd>
<dt>
<a name = "ACCEPT_NON_EMPTY_STRING"></a>
<strong>ACCEPT_NON_EMPTY_STRING (value)</strong>
</dt>
<dd>
An accept function that only accepts non empty string values.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
The value that is checked.
</li>
</ul>
<h3>Returns:</h3>
<ol>
true if the given value is a not empty string value.
</ol>
</dd>
<dt>
<a name = "List:new"></a>
<strong>List:new (...)</strong>
</dt>
<dd>
Creates a new instance of List.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
Optional. A list of values to add.
</li>
</ul>
<h3>Returns:</h3>
<ol>
A new instance of List.
</ol>
</dd>
<dt>
<a name = "List:add"></a>
<strong>List:add (...)</strong>
</dt>
<dd>
Adds the given items to the list.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
The items to add.
</li>
</ul>
</dd>
<dt>
<a name = "List:add_list"></a>
<strong>List:add_list (...)</strong>
</dt>
<dd>
Adds the given List to the list.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
The Lists to add.
</li>
</ul>
</dd>
<dt>
<a name = "List:clear"></a>
<strong>List:clear ()</strong>
</dt>
<dd>
Clears all entries from the list.
</dd>
<dt>
<a name = "List:contains"></a>
<strong>List:contains (item)</strong>
</dt>
<dd>
Checks if this list contains the given item.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">item</span>
The item to search for.
</li>
</ul>
<h3>Returns:</h3>
<ol>
true if this list contains the given item.
</ol>
</dd>
<dt>
<a name = "List:cull_duplicates"></a>
<strong>List:cull_duplicates (comparator)</strong>
</dt>
<dd>
Culls/removes all duplicates from this list.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">comparator</span>
Optional. The comparator to be used. Accepts two values
and returns true if they can be considered equal. Defaults
to testing the identity.
</li>
</ul>
</dd>
<dt>
<a name = "List:foreach"></a>
<strong>List:foreach (action)</strong>
</dt>
<dd>
Iterates over all items in the list and invokes the given action on them.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">action</span>
The function to invoke on the item, the first parameter will be
the item itself, the second (optional) parameter is the index.
The function can return true to stop iterating over the items.
</li>
</ul>
</dd>
<dt>
<a name = "List:get"></a>
<strong>List:get (index)</strong>
</dt>
<dd>
Gets the item at the given index. Returns nil if there is no item.
Note that there is no different between "no item" and "nil is the item",
in both cases nil is returned.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">index</span>
The index of the item to get.
</li>
</ul>
<h3>Returns:</h3>
<ol>
The item at the given index. nil if there is no item.
</ol>
</dd>
<dt>
<a name = "List:get_first"></a>
<strong>List:get_first (accept)</strong>
</dt>
<dd>
Gets the first value in this List that is accepted by the given function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">accept</span>
Optional. The function to accept values. Accepts the value and
returns a boolean, true if the value is accepted. If nil
the first value in the list will be returned.
</li>
</ul>
<h3>Returns:</h3>
<ol>
The first accepted value, or if none was accepted, nil.
</ol>
</dd>
<dt>
<a name = "List:get_last"></a>
<strong>List:get_last (accept)</strong>
</dt>
<dd>
Gets the last value in this List that is accepted by the given function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">accept</span>
Optional. The function to accept values. Accepts the value and
returns a boolean, true if the value is accepted. If nil
the last value in the list will be returned.
</li>
</ul>
<h3>Returns:</h3>
<ol>
The last accepted value, or if none was accepted, nil.
</ol>
</dd>
<dt>
<a name = "List:index"></a>
<strong>List:index (item, equals)</strong>
</dt>
<dd>
Returns the index of the given item.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">item</span>
The item for which to get the index.
</li>
<li><span class="parameter">equals</span>
Optional. The equals function to use.
</li>
</ul>
<h3>Returns:</h3>
<ol>
The index of the given item. -1 if this item is not in this list.
</ol>
</dd>
<dt>
<a name = "List:invoke"></a>
<strong>List:invoke (...)</strong>
</dt>
<dd>
If the List contains functions, this invokes all items with the given
parameters.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
The parameters to invoke the functions.
</li>
</ul>
</dd>
<dt>
<a name = "List:is_empty"></a>
<strong>List:is_empty ()</strong>
</dt>
<dd>
Gets if this List is empty.
<h3>Returns:</h3>
<ol>
true if this List is empty.
</ol>
</dd>
<dt>
<a name = "List:matching"></a>
<strong>List:matching (condition)</strong>
</dt>
<dd>
Returns a List with all items that match the given condition.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">condition</span>
The condition, a function that accepts one parameter,
the item, and returns a boolean.
</li>
</ul>
<h3>Returns:</h3>
<ol>
The List of matching items.
</ol>
</dd>
<dt>
<a name = "List:remove"></a>
<strong>List:remove (...)</strong>
</dt>
<dd>
Removes the given values from the list.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
The values to remove.
</li>
</ul>
</dd>
<dt>
<a name = "List:remove_index"></a>
<strong>List:remove_index (...)</strong>
</dt>
<dd>
Removes the given index from the list.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
The index to remove.
</li>
</ul>
</dd>
<dt>
<a name = "List:return_first"></a>
<strong>List:return_first (accept, ...)</strong>
</dt>
<dd>
Invokes the contained functions and returns the first value that is accepted
by the given function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">accept</span>
The function to accept values, takes the value and returns
a boolean, true if the value is accepted.
</li>
<li><span class="parameter">...</span>
Optional. The parameters to invoke the functions with.
</li>
</ul>
<h3>Returns:</h3>
<ol>
The first accepted return value, nil if none was accepted.
</ol>
</dd>
<dt>
<a name = "List:return_last"></a>
<strong>List:return_last (accept, ...)</strong>
</dt>
<dd>
Invokes the contained functions and returns the last value that is accepted
by the given function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">accept</span>
The function to accept values, takes the value and returns
a boolean, true if the value is accepted.
</li>
<li><span class="parameter">...</span>
Optional. The parameters to invoke the functions with.
</li>
</ul>
<h3>Returns:</h3>
<ol>
The last accepted return value, nil if none was accepted.
</ol>
</dd>
<dt>
<a name = "List:size"></a>
<strong>List:size ()</strong>
</dt>
<dd>
Gets the size of the list.
<h3>Returns:</h3>
<ol>
The size of the list.
</ol>
</dd>
<dt>
<a name = "List:sort"></a>
<strong>List:sort (comparator)</strong>
</dt>
<dd>
Sorts this List.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">comparator</span>
Optional. The comparator to be used. Accepts two values
and returns a boolean, true if the first is parameter is
less than the second.
</li>
</ul>
</dd>
<dt>
<a name = "List:sub_list"></a>
<strong>List:sub_list (from, count)</strong>
</dt>
<dd>
Gets a sub list starting from the given index and the given number of items.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">from</span>
The starting index.
</li>
<li><span class="parameter">count</span>
The count of items to get.
</li>
</ul>
<h3>Returns:</h3>
<ol>
A List containing the items starting by the given index. The List
will be empty if the starting index is out of range, if there are not
as many items as specified with count, all items that there are will
be returned.
</ol>
</dd>
<dt>
<a name = "List:to_table"></a>
<strong>List:to_table ()</strong>
</dt>
<dd>
Turns this list into a table, the return table will be a one indexed array,
and can freely be modified as it is not the table used by this instance.
However the items in the returned table are not copies.
<h3>Returns:</h3>
<ol>
This list as table.
</ol>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.2</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>