Files
factorio-scenario-ExpCluster/doc/modules/StdLib.Table.html
Cooldude2606 4d05f13cb3 Updated Doc
2018-06-01 16:30:32 +01:00

1131 lines
38 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>Reference</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>ldoc</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="nowrap">
<li><a href="../modules/FSM.html">FSM</a></li>
<li><a href="../modules/modules.expgamingcore.commands.control.html">modules.expgamingcore.commands.control</a></li>
<li><a href="../modules/modules.expgamingcore.gui.guiparts.center.html">modules.expgamingcore.gui.guiparts.center</a></li>
<li><a href="../modules/modules.expgamingcore.gui.guiparts.inputs.html">modules.expgamingcore.gui.guiparts.inputs</a></li>
<li><a href="../modules/modules.expgamingcore.gui.guiparts.left.html">modules.expgamingcore.gui.guiparts.left</a></li>
<li><a href="../modules/modules.expgamingcore.gui.guiparts.popup.html">modules.expgamingcore.gui.guiparts.popup</a></li>
<li><a href="../modules/modules.expgamingcore.gui.guiparts.toolbar.html">modules.expgamingcore.gui.guiparts.toolbar</a></li>
<li><a href="../modules/modules.expgamingcore.gui.control.html">modules.expgamingcore.gui.control</a></li>
<li><a href="../modules/modules.expgamingcore.ranking.control.html">modules.expgamingcore.ranking.control</a></li>
<li><a href="../modules/ExpGamingCore.Server.html">ExpGamingCore.Server</a></li>
<li><a href="../modules/ExpGamingCore.Sync.html">ExpGamingCore.Sync</a></li>
<li><a href="../modules/ExpGamingLib.html">ExpGamingLib</a></li>
<li><a href="../modules/StdLib.Color.html">StdLib.Color</a></li>
<li><a href="../modules/StdLib.Game.html">StdLib.Game</a></li>
<li><a href="../modules/StdLib.String.html">StdLib.String</a></li>
<li><strong>StdLib.Table</strong></li>
<li><a href="../modules/StdLib.Time.html">StdLib.Time</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>StdLib.Table</code></h1>
<p>Extends Lua 5.2 table.</p>
<p></p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#map">map (tbl, func[, ...])</a></td>
<td class="summary">Given a mapping function, creates a transformed copy of the table
by calling the function for each element in the table, and using
the result as the new value for the key.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#filter">filter (tbl, func[, ...])</a></td>
<td class="summary">Given a filter function, creates a filtered copy of the table
by calling the function for each element in the table, and
filtering out any key-value pairs for non-true results.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#find">find (tbl, func[, ...])</a></td>
<td class="summary">Given a candidate search function, iterates over the table, calling the function
for each element in the table, and returns the first element the search function returned true.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#any">any (tbl, func[, ...])</a></td>
<td class="summary">Given a candidate search function, iterates over the table, calling the function
for each element in the table, and returns true if search function returned true.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#each">each (tbl, func[, ...])</a></td>
<td class="summary">Given a function, apply it to each element in the table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#flatten">flatten (tbl[, level])</a></td>
<td class="summary">Returns a new array that is a one-dimensional recursive flattening of the given array.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#first">first (tbl)</a></td>
<td class="summary">Given an array, returns the first element or nil if no element exists.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#last">last (tbl)</a></td>
<td class="summary">Given an array, returns the last element or nil if no elements exist.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#min">min (tbl)</a></td>
<td class="summary">Given an array of only numeric values, returns the minimum or nil if no element exists.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#max">max (tbl)</a></td>
<td class="summary">Given an array of only numeric values, returns the maximum or nil if no element exists.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sum">sum (tbl)</a></td>
<td class="summary">Given an array of only numeric values, return the sum of all values, or 0 for empty arrays.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#avg">avg (tbl)</a></td>
<td class="summary">Given an array of only numeric values, returns the average or nil if no element exists.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#merge">merge (tblA, tblB[, array_merge=false])</a></td>
<td class="summary">Merges two tables &mdash; values from first get overwritten by the second.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#deepcopy">deepcopy (object)</a></td>
<td class="summary">Creates a deep copy of table without copying Factorio objects.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#values">values (tbl[, sorted[, as_string]])</a></td>
<td class="summary">Returns a copy of all of the values in the table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#keys">keys (tbl[, sorted[, as_string]])</a></td>
<td class="summary">Returns a copy of all of the keys in the table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#remove_keys">remove_keys (tbl, keys)</a></td>
<td class="summary">Removes keys from a table by setting the values associated with the keys to nil.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#count_keys">count_keys (tbl[, func[, ...]])</a></td>
<td class="summary">Returns the number of keys in a table, if func is passed only count keys when the function is true.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#invert">invert (tbl)</a></td>
<td class="summary">Returns an inverted (***{[value] = key,...}***) copy of the given table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#size">size (table)</a></td>
<td class="summary">Return the size of a table using built in table_size function</td>
</tr>
<tr>
<td class="name" nowrap><a href="#arr_to_bool">arr_to_bool (tbl)</a></td>
<td class="summary">For all string or number values in an array map them to a key = true table</td>
</tr>
<tr>
<td class="name" nowrap><a href="#key_to_str">key_to_str (k)</a></td>
<td class="summary">Returns a value in a form able to be read as a key</td>
</tr>
<tr>
<td class="name" nowrap><a href="#tostring">tostring (tbl)</a></td>
<td class="summary">Returns a table in a form able to be read as a table</td>
</tr>
<tr>
<td class="name" nowrap><a href="#json">json (lua_table)</a></td>
<td class="summary">Simmilar to table.tostring but converts a lua table to a json one</td>
</tr>
<tr>
<td class="name" nowrap><a href="#autokey">autokey (tbl, str)</a></td>
<td class="summary">Returns the closest match to a key</td>
</tr>
<tr>
<td class="name" nowrap><a href="#alphanumsort">alphanumsort (tbl)</a></td>
<td class="summary">Returns the list is a sorted way that would be expected by people (this is by key)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#keysort">keysort (tbl)</a></td>
<td class="summary">Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "map"></a>
<strong>map (tbl, func[, ...])</strong>
</dt>
<dd>
Given a mapping function, creates a transformed copy of the table
by calling the function for each element in the table, and using
the result as the new value for the key. Passes the index as second argument to the function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to be mapped to the transform
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">function</span></span>
the function to transform values
</li>
<li><span class="parameter">...</span>
additional arguments passed to the function
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
a new table containing the keys and mapped values
</ol>
<h3>Usage:</h3>
<ul>
<li><pre class="example">a= { <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>}
<span class="global">table</span>.map(a, <span class="keyword">function</span>(v) <span class="keyword">return</span> v * <span class="number">10</span> <span class="keyword">end</span>) <span class="comment">--produces: { 10, 20, 30, 40, 50 }</span></pre></li>
<li><pre class="example">a = {<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>}
<span class="global">table</span>.map(a, <span class="keyword">function</span>(v, k, x) <span class="keyword">return</span> v * k + x <span class="keyword">end</span>, <span class="number">100</span>) <span class="comment">--produces { 101, 104, 109, 116, 125}</span></pre></li>
</ul>
</dd>
<dt>
<a name = "filter"></a>
<strong>filter (tbl, func[, ...])</strong>
</dt>
<dd>
Given a filter function, creates a filtered copy of the table
by calling the function for each element in the table, and
filtering out any key-value pairs for non-true results. Passes the index as second argument to the function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to be filtered
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">function</span></span>
the function to filter values
</li>
<li><span class="parameter">...</span>
additional arguments passed to the function
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
a new table containing the filtered key-value pairs
</ol>
<h3>Usage:</h3>
<ul>
<li><pre class="example">a= { <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>}
<span class="global">table</span>.filter(a, <span class="keyword">function</span>(v) <span class="keyword">return</span> v % <span class="number">2</span> == <span class="number">0</span> <span class="keyword">end</span>) <span class="comment">--produces: { 2, 4 }</span></pre></li>
<li><pre class="example">a = {<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>}
<span class="global">table</span>.filter(a, <span class="keyword">function</span>(v, k, x) <span class="keyword">return</span> k % <span class="number">2</span> == <span class="number">1</span> <span class="keyword">end</span>) <span class="comment">--produces: { 1, 3, 5 }</span></pre></li>
</ul>
</dd>
<dt>
<a name = "find"></a>
<strong>find (tbl, func[, ...])</strong>
</dt>
<dd>
Given a candidate search function, iterates over the table, calling the function
for each element in the table, and returns the first element the search function returned true.
Passes the index as second argument to the function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to be searched
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">function</span></span>
the function to use to search for any matching element
</li>
<li><span class="parameter">...</span>
additional arguments passed to the function
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">nil</span> or <span class="type">Mixed</span></span>
the first found value, or nil if none was found
</ol>
<h3>Usage:</h3>
<ul>
<li><pre class="example">a= { <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>}
<span class="global">table</span>.find(a, <span class="keyword">function</span>(v) <span class="keyword">return</span> v % <span class="number">2</span> == <span class="number">0</span> <span class="keyword">end</span>) <span class="comment">--produces: 2</span></pre></li>
<li><pre class="example">a = {<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>}
<span class="global">table</span>.find(a, <span class="keyword">function</span>(v, k, x) <span class="keyword">return</span> k % <span class="number">2</span> == <span class="number">1</span> <span class="keyword">end</span>) <span class="comment">--produces: 1</span></pre></li>
</ul>
</dd>
<dt>
<a name = "any"></a>
<strong>any (tbl, func[, ...])</strong>
</dt>
<dd>
Given a candidate search function, iterates over the table, calling the function
for each element in the table, and returns true if search function returned true.
Passes the index as second argument to the function.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to be searched
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">function</span></span>
the function to use to search for any matching element
</li>
<li><span class="parameter">...</span>
additional arguments passed to the function
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
true if an element was found, false if none was found
</ol>
<h3>Usage:</h3>
<ul>
<li><pre class="example">a= { <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>} <span class="global">table</span>.any(a, <span class="keyword">function</span>(v) <span class="keyword">return</span> v % <span class="number">2</span> == <span class="number">0</span> <span class="keyword">end</span>) <span class="comment">--produces: true</span></pre></li>
<li><pre class="example">a = {<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>} <span class="global">table</span>.any(a, <span class="keyword">function</span>(v, k, x) <span class="keyword">return</span> k % <span class="number">2</span> == <span class="number">1</span> <span class="keyword">end</span>) <span class="comment">--produces: true</span></pre></li>
</ul>
</dd>
<dt>
<a name = "each"></a>
<strong>each (tbl, func[, ...])</strong>
</dt>
<dd>
Given a function, apply it to each element in the table.
Passes the index as the second argument to the function.
<p>Iteration is aborted if the applied function returns true for any element during iteration.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to be iterated
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">function</span></span>
the function to apply to elements
</li>
<li><span class="parameter">...</span>
additional arguments passed to the function
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table where the given function has been applied to its elements
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example">a = {<span class="number">10</span>, <span class="number">20</span>, <span class="number">30</span>, <span class="number">40</span>}
<span class="global">table</span>.each(a, <span class="keyword">function</span>(v) game.<span class="global">print</span>(v) <span class="keyword">end</span>) <span class="comment">--prints 10, 20, 30, 40, 50</span></pre>
</ul>
</dd>
<dt>
<a name = "flatten"></a>
<strong>flatten (tbl[, level])</strong>
</dt>
<dd>
Returns a new array that is a one-dimensional recursive flattening of the given array.
For every element that is an array, extract its elements into the new array.
<p>The optional level argument determines the level of recursion to flatten.
> This function flattens an integer-indexed array, but not an associative array.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><span class="type">array</span></span>
the array to be flattened
</li>
<li><span class="parameter">level</span>
<span class="types"><span class="type">uint</span></span>
recursive levels, or no limit to recursion if not supplied
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">array</span></span>
a new array that represents the flattened contents of the given array
</ol>
</dd>
<dt>
<a name = "first"></a>
<strong>first (tbl)</strong>
</dt>
<dd>
Given an array, returns the first element or nil if no element exists.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><span class="type">array</span></span>
the array
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">nil</span> or <span class="type">Mixed</span></span>
the first element
</ol>
</dd>
<dt>
<a name = "last"></a>
<strong>last (tbl)</strong>
</dt>
<dd>
Given an array, returns the last element or nil if no elements exist.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><span class="type">array</span></span>
the array
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">nil</span> or <span class="type">Mixed</span></span>
the last element or nil
</ol>
</dd>
<dt>
<a name = "min"></a>
<strong>min (tbl)</strong>
</dt>
<dd>
Given an array of only numeric values, returns the minimum or nil if no element exists.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><span class="type">{number,...}</span></span>
the array with only numeric values
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">nil</span> or <span class="type">number</span></span>
the minimum value
</ol>
</dd>
<dt>
<a name = "max"></a>
<strong>max (tbl)</strong>
</dt>
<dd>
Given an array of only numeric values, returns the maximum or nil if no element exists.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><span class="type">{number,...}</span></span>
the array with only numeric values
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">nil</span> or <span class="type">number</span></span>
the maximum value
</ol>
</dd>
<dt>
<a name = "sum"></a>
<strong>sum (tbl)</strong>
</dt>
<dd>
Given an array of only numeric values, return the sum of all values, or 0 for empty arrays.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><span class="type">{number,...}</span></span>
the array with only numeric values
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">number</span></span>
the sum of the numbers or zero if the given array was empty
</ol>
</dd>
<dt>
<a name = "avg"></a>
<strong>avg (tbl)</strong>
</dt>
<dd>
Given an array of only numeric values, returns the average or nil if no element exists.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><span class="type">{number,...}</span></span>
the array with only numeric values
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">nil</span> or <span class="type">number</span></span>
the average value
</ol>
</dd>
<dt>
<a name = "merge"></a>
<strong>merge (tblA, tblB[, array_merge=false])</strong>
</dt>
<dd>
Merges two tables &mdash; values from first get overwritten by the second.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tblA</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
first table
</li>
<li><span class="parameter">tblB</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
second table
</li>
<li><span class="parameter">array_merge</span>
<span class="types"><span class="type">boolean</span></span>
set to true to merge the tables as an array or false for an associative array
(<em>default</em> false)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">array</span> or <a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
an array or an associated array where tblA and tblB have been merged
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">function</span> some_func(x, y, args)
args = <span class="global">table</span>.merge({option1=<span class="keyword">false</span>}, args)
<span class="keyword">if</span> opts.option1 == <span class="keyword">true</span> <span class="keyword">then</span> <span class="keyword">return</span> x <span class="keyword">else</span> <span class="keyword">return</span> y <span class="keyword">end</span>
<span class="keyword">end</span>
some_func(<span class="number">1</span>,<span class="number">2</span>) <span class="comment">-- returns 2
</span>some_func(<span class="number">1</span>,<span class="number">2</span>,{option1=<span class="keyword">true</span>}) <span class="comment">-- returns 1</span></pre>
</ul>
</dd>
<dt>
<a name = "deepcopy"></a>
<strong>deepcopy (object)</strong>
</dt>
<dd>
Creates a deep copy of table without copying Factorio objects.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">object</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to copy
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
a copy of the table
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> copy = <span class="global">table</span>.deepcopy[data.raw.[<span class="string">"stone-furnace"</span>][<span class="string">"stone-furnace"</span>]] <span class="comment">-- returns a copy of the stone furnace entity</span></pre>
</ul>
</dd>
<dt>
<a name = "values"></a>
<strong>values (tbl[, sorted[, as_string]])</strong>
</dt>
<dd>
Returns a copy of all of the values in the table.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to copy the keys from, or an empty table if tbl is nil
</li>
<li><span class="parameter">sorted</span>
<span class="types"><span class="type">boolean</span></span>
whether to sort the keys (slower) or keep the random order from pairs()
(<em>optional</em>)
</li>
<li><span class="parameter">as_string</span>
<span class="types"><span class="type">boolean</span></span>
whether to try and parse the values as strings, or leave them as their existing type
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">array</span></span>
an array with a copy of all the values in the table
</ol>
</dd>
<dt>
<a name = "keys"></a>
<strong>keys (tbl[, sorted[, as_string]])</strong>
</dt>
<dd>
Returns a copy of all of the keys in the table.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to copy the keys from, or an empty table if tbl is nil
</li>
<li><span class="parameter">sorted</span>
<span class="types"><span class="type">boolean</span></span>
whether to sort the keys (slower) or keep the random order from pairs()
(<em>optional</em>)
</li>
<li><span class="parameter">as_string</span>
<span class="types"><span class="type">boolean</span></span>
whether to try and parse the keys as strings, or leave them as their existing type
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">array</span></span>
an array with a copy of all the keys in the table
</ol>
</dd>
<dt>
<a name = "remove_keys"></a>
<strong>remove_keys (tbl, keys)</strong>
</dt>
<dd>
Removes keys from a table by setting the values associated with the keys to nil.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to remove the keys from
</li>
<li><span class="parameter">keys</span>
<span class="types"><span class="type">{Mixed,...}</span></span>
an array of keys that exist in the given table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
tbl without the specified keys
</ol>
<h3>Usage:</h3>
<ul>
<li><pre class="example"><span class="keyword">local</span> a = {<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>}
<span class="global">table</span>.remove_keys(a, {<span class="number">1</span>,<span class="number">3</span>}) <span class="comment">--returns {nil, 2, nil, 4}</span></pre></li>
<li><pre class="example"><span class="keyword">local</span> b = {k1 = <span class="number">1</span>, k2 = <span class="string">'foo'</span>, old_key = <span class="string">'bar'</span>}
<span class="global">table</span>.remove_keys(b, {<span class="string">'old_key'</span>}) <span class="comment">--returns {k1 = 1, k2 = 'foo'}</span></pre></li>
</ul>
</dd>
<dt>
<a name = "count_keys"></a>
<strong>count_keys (tbl[, func[, ...]])</strong>
</dt>
<dd>
Returns the number of keys in a table, if func is passed only count keys when the function is true.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
to count keys
</li>
<li><span class="parameter">func</span>
<span class="types"><span class="type">function</span></span>
to incremement counter
(<em>optional</em>)
</li>
<li><span class="parameter">...</span>
additional arguments passed to the function
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">number</span></span>
The number of keys matching the function or the number of all keys if func isn't passed</li>
<li>
<span class="types"><span class="type">number</span></span>
The total number of keys</li>
</ol>
<h3>Usage:</h3>
<ul>
<li><pre class="example"><span class="keyword">local</span> a = { <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>}
<span class="global">table</span>.count_keys(a) <span class="comment">-- produces: 5, 5</span></pre></li>
<li><pre class="example"><span class="keyword">local</span> a = {<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>}
<span class="global">table</span>.count_keys(a, <span class="keyword">function</span>(v, k) <span class="keyword">return</span> k % <span class="number">2</span> == <span class="number">1</span> <span class="keyword">end</span>) <span class="comment">-- produces: 3, 5</span></pre></li>
</ul>
</dd>
<dt>
<a name = "invert"></a>
<strong>invert (tbl)</strong>
</dt>
<dd>
Returns an inverted (***{[value] = key,...}***) copy of the given table. If the values are not unique, the assigned key depends on the order of pairs().
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to invert
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
a new table with inverted mapping
</ol>
<h3>Usage:</h3>
<ul>
<li><pre class="example"><span class="keyword">local</span> a = {k1 = <span class="string">'foo'</span>, k2 = <span class="string">'bar'</span>}
<span class="global">table</span>.invert(a) <span class="comment">--returns {'foo' = k1, 'bar' = k2}</span></pre></li>
<li><pre class="example"><span class="keyword">local</span> b = {k1 = <span class="string">'foo'</span>, k2 = <span class="string">'bar'</span>, k3 = <span class="string">'bar'</span>}
<span class="global">table</span>.invert(b) <span class="comment">--returns {'foo' = k1, 'bar' = ?}</span></pre></li>
</ul>
</dd>
<dt>
<a name = "size"></a>
<strong>size (table)</strong>
</dt>
<dd>
Return the size of a table using built in table_size function
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">table</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
to use
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">int</span></span>
size of the table
</ol>
</dd>
<dt>
<a name = "arr_to_bool"></a>
<strong>arr_to_bool (tbl)</strong>
</dt>
<dd>
For all string or number values in an array map them to a key = true table
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to convert
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the converted table
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> a = {<span class="string">"v1"</span>, <span class="string">"v2"</span>}
<span class="global">table</span>.array_to_dict_bool(a) <span class="comment">-- return {["v1"] = true, ["v2"]= true}</span></pre>
</ul>
</dd>
<dt>
<a name = "key_to_str"></a>
<strong>key_to_str (k)</strong>
</dt>
<dd>
Returns a value in a form able to be read as a key
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">k</span>
key to convert
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.4">string</a></span>
the converted key
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> a = <span class="string">'key'</span>
<span class="global">table</span>.key_to_str(a) <span class="comment">-- return '["key"]'</span></pre>
</ul>
</dd>
<dt>
<a name = "tostring"></a>
<strong>tostring (tbl)</strong>
</dt>
<dd>
Returns a table in a form able to be read as a table
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
table to convert
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.4">string</a></span>
the converted table
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> a = {k1=<span class="string">'foo'</span>,k2=<span class="string">'bar'</span>}
<span class="global">table</span>.<span class="global">tostring</span>(a) <span class="comment">-- return '{["k1"]="foo",["k2"]="bar"}'</span></pre>
</ul>
</dd>
<dt>
<a name = "json"></a>
<strong>json (lua_table)</strong>
</dt>
<dd>
Simmilar to table.tostring but converts a lua table to a json one
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">lua_table</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to convert
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.4">string</a></span>
the table in a json format
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> a = {k1=<span class="string">'foo'</span>,k2=<span class="string">'bar'</span>}
talbe.json(a) <span class="comment">-- return '{"k1":"foo","k2":"bar"}'</span></pre>
</ul>
</dd>
<dt>
<a name = "autokey"></a>
<strong>autokey (tbl, str)</strong>
</dt>
<dd>
Returns the closest match to a key
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
</li>
<li><span class="parameter">str</span>
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">tbl = {foo=<span class="number">1</span>,bar=<span class="number">2</span>}
<span class="global">table</span>.autokey(tbl,<span class="string">'f'</span>) <span class="comment">-- return 1</span></pre>
</ul>
</dd>
<dt>
<a name = "alphanumsort"></a>
<strong>alphanumsort (tbl)</strong>
</dt>
<dd>
Returns the list is a sorted way that would be expected by people (this is by key)
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to be sorted
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the sorted table
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example">tbl = <span class="global">table</span>.alphanumsort(tbl)</pre>
</ul>
</dd>
<dt>
<a name = "keysort"></a>
<strong>keysort (tbl)</strong>
</dt>
<dd>
Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the table to be sorted
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.2/manual.html#6.5">table</a></span>
the sorted table
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example">tbl = <span class="global">table</span>.alphanumsort(tbl)</pre>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2018-06-01 16:29:39 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>