Files
factorio-scenario-ExpCluster/doc/modules/utils.table.html
Cooldude2606 e187059ae0 Ldoc compliant
2019-05-29 22:24:04 +01:00

584 lines
16 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>
<li><a href="#Fields">Fields</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/config._file_loader.html">config._file_loader</a></li>
<li><a href="../modules/config.action_buttons.html">config.action_buttons</a></li>
<li><a href="../modules/config.advanced_start.html">config.advanced_start</a></li>
<li><a href="../modules/config.death_logger.html">config.death_logger</a></li>
<li><a href="../modules/config.expcore-commands.auth_admin.html">config.expcore-commands.auth_admin</a></li>
<li><a href="../modules/config.expcore-commands.auth_roles.html">config.expcore-commands.auth_roles</a></li>
<li><a href="../modules/config.expcore-commands.auth_runtime_disable.html">config.expcore-commands.auth_runtime_disable</a></li>
<li><a href="../modules/config.expcore-commands.parse_general.html">config.expcore-commands.parse_general</a></li>
<li><a href="../modules/config.expcore-commands.parse_roles.html">config.expcore-commands.parse_roles</a></li>
<li><a href="../modules/config.permission_groups.html">config.permission_groups</a></li>
<li><a href="../modules/config.popup_messages.html">config.popup_messages</a></li>
<li><a href="../modules/config.rockets.html">config.rockets</a></li>
<li><a href="../modules/config.roles.html">config.roles</a></li>
<li><a href="../modules/config.scorched_earth.html">config.scorched_earth</a></li>
<li><a href="../modules/config.spawn_area.html">config.spawn_area</a></li>
<li><a href="../modules/config.warnings.html">config.warnings</a></li>
<li><a href="../modules/control.html">control</a></li>
<li><a href="../modules/Commands.html">Commands</a></li>
<li><a href="../modules/Public.html">Public</a></li>
<li><a href="../modules/expcore.gui.html">expcore.gui</a></li>
<li><a href="../modules/expcore.gui.buttons.html">expcore.gui.buttons</a></li>
<li><a href="../modules/expcore.gui.center.html">expcore.gui.center</a></li>
<li><a href="../modules/expcore.gui.checkboxs.html">expcore.gui.checkboxs</a></li>
<li><a href="../modules/expcore.gui.core.html">expcore.gui.core</a></li>
<li><a href="../modules/expcore.gui.dropdown.html">expcore.gui.dropdown</a></li>
<li><a href="../modules/expcore.gui.elem-button.html">expcore.gui.elem-button</a></li>
<li><a href="../modules/expcore.gui.instances.html">expcore.gui.instances</a></li>
<li><a href="../modules/expcore.gui.left.html">expcore.gui.left</a></li>
<li><a href="../modules/expcore.gui.popups.html">expcore.gui.popups</a></li>
<li><a href="../modules/expcore.gui.progress-bar.html">expcore.gui.progress-bar</a></li>
<li><a href="../modules/expcore.gui.slider.html">expcore.gui.slider</a></li>
<li><a href="../modules/expcore.gui.test.html">expcore.gui.test</a></li>
<li><a href="../modules/expcore.gui.text.html">expcore.gui.text</a></li>
<li><a href="../modules/expcore.gui.toolbar.html">expcore.gui.toolbar</a></li>
<li><a href="../modules/Permissions_Groups.html">Permissions_Groups</a></li>
<li><a href="../modules/Commands.html">Commands</a></li>
<li><a href="../modules/expcore.store.html">expcore.store</a></li>
<li><a href="../modules/modules.addons.advanced-start.html">modules.addons.advanced-start</a></li>
<li><a href="../modules/modules.addons.chat-popups.html">modules.addons.chat-popups</a></li>
<li><a href="../modules/modules.addons.damage-popups.html">modules.addons.damage-popups</a></li>
<li><a href="../modules/modules.gui.player-list.html">modules.gui.player-list</a></li>
<li><a href="../modules/modules.gui.rocket-info.html">modules.gui.rocket-info</a></li>
<li><a href="../modules/modules.gui.science-info.html">modules.gui.science-info</a></li>
<li><a href="../modules/modules.gui.task-list.html">modules.gui.task-list</a></li>
<li><a href="../modules/utils.alien_evolution_progress.html">utils.alien_evolution_progress</a></li>
<li><a href="../modules/utils.core.html">utils.core</a></li>
<li><a href="../modules/utils.debug.html">utils.debug</a></li>
<li><a href="../modules/utils.event.html">utils.event</a></li>
<li><a href="../modules/utils.event_core.html">utils.event_core</a></li>
<li><a href="../modules/utils.math.html">utils.math</a></li>
<li><a href="../modules/utils.recipe_locker.html">utils.recipe_locker</a></li>
<li><a href="../modules/utils.state_machine.html">utils.state_machine</a></li>
<li><strong>utils.table</strong></li>
<li><a href="../modules/utils.task.html">utils.task</a></li>
<li><a href="../modules/utils.timestamp.html">utils.timestamp</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>utils.table</code></h1>
<p>Searches a table to remove a specific element without an index</p>
<p></p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#fast_remove">fast_remove (tbl, index)</a></td>
<td class="summary">Removes an item from an array in O(1) time.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#add_all">add_all (t1, t2)</a></td>
<td class="summary">Adds the contents of table t2 to table t1</td>
</tr>
<tr>
<td class="name" nowrap><a href="#index_of">index_of (t, e)</a></td>
<td class="summary">Checks if a table contains an element</td>
</tr>
<tr>
<td class="name" nowrap><a href="#index_of_in_array">index_of_in_array (t, e)</a></td>
<td class="summary">Checks if the arrayed portion of a table contains an element</td>
</tr>
<tr>
<td class="name" nowrap><a href="#contains">contains (t, e)</a></td>
<td class="summary">Checks if a table contains an element</td>
</tr>
<tr>
<td class="name" nowrap><a href="#array_contains">array_contains (t, e)</a></td>
<td class="summary">Checks if the arrayed portion of a table contains an element</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set">set (t, index, element)</a></td>
<td class="summary">Adds an element into a specific index position while shuffling the rest down</td>
</tr>
<tr>
<td class="name" nowrap><a href="#get_random_dictionary_entry">get_random_dictionary_entry (t, key)</a></td>
<td class="summary">Chooses a random entry from a table
because this uses math.random, it cannot be used outside of events</td>
</tr>
<tr>
<td class="name" nowrap><a href="#get_random_weighted">get_random_weighted (weight_table, item_index, weight_index)</a></td>
<td class="summary">Chooses a random entry from a weighted table
because this uses math.random, it cannot be used outside of events</td>
</tr>
<tr>
<td class="name" nowrap><a href="#shuffle_table">shuffle_table (t)</a></td>
<td class="summary">Creates a fisher-yates shuffle of a sequential number-indexed table
because this uses math.random, it cannot be used outside of events if no rng is supplied
from: http://www.sdknews.com/cross-platform/corona/tutorial-how-to-shuffle-table-items</td>
</tr>
<tr>
<td class="name" nowrap><a href="#clear_table">clear_table (t, array)</a></td>
<td class="summary">Clears all existing entries in a table</td>
</tr>
</table>
<h2><a href="#Fields">Fields</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#inspect">inspect</a></td>
<td class="summary">Similar to serpent.block, returns a string with a pretty representation of a table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#size">size</a></td>
<td class="summary">Takes a table and returns the number of entries in the table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#deep_copy">deep_copy</a></td>
<td class="summary">Creates a deepcopy of a table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#merge">merge</a></td>
<td class="summary">Merges multiple tables.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#equals">equals</a></td>
<td class="summary">Determines if two tables are structurally equal.</td>
</tr>
</table>
<br/>
<br/>
<h2><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "fast_remove"></a>
<strong>fast_remove (tbl, index)</strong>
</dt>
<dd>
Removes an item from an array in O(1) time.
The catch is that fast_remove doesn't guarantee to maintain the order of items in the array.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">tbl</span>
<table> arrayed table
</li>
<li><span class="parameter">index</span>
<number> Must be >= 0. The case where index > #tbl is handled.
</li>
</ul>
</dd>
<dt>
<a name = "add_all"></a>
<strong>add_all (t1, t2)</strong>
</dt>
<dd>
Adds the contents of table t2 to table t1
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t1</span>
<table> to insert into
</li>
<li><span class="parameter">t2</span>
<table> to insert from
</li>
</ul>
</dd>
<dt>
<a name = "index_of"></a>
<strong>index_of (t, e)</strong>
</dt>
<dd>
Checks if a table contains an element
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<table>
</li>
<li><span class="parameter">e</span>
<any> table element
</li>
</ul>
</dd>
<dt>
<a name = "index_of_in_array"></a>
<strong>index_of_in_array (t, e)</strong>
</dt>
<dd>
Checks if the arrayed portion of a table contains an element
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<table>
</li>
<li><span class="parameter">e</span>
<any> table element
</li>
</ul>
</dd>
<dt>
<a name = "contains"></a>
<strong>contains (t, e)</strong>
</dt>
<dd>
Checks if a table contains an element
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<table>
</li>
<li><span class="parameter">e</span>
<any> table element
</li>
</ul>
</dd>
<dt>
<a name = "array_contains"></a>
<strong>array_contains (t, e)</strong>
</dt>
<dd>
Checks if the arrayed portion of a table contains an element
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<table>
</li>
<li><span class="parameter">e</span>
<any> table element
</li>
</ul>
</dd>
<dt>
<a name = "set"></a>
<strong>set (t, index, element)</strong>
</dt>
<dd>
Adds an element into a specific index position while shuffling the rest down
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<table> to add into
</li>
<li><span class="parameter">index</span>
<number> the position in the table to add to
</li>
<li><span class="parameter">element</span>
<any> to add to the table
</li>
</ul>
</dd>
<dt>
<a name = "get_random_dictionary_entry"></a>
<strong>get_random_dictionary_entry (t, key)</strong>
</dt>
<dd>
Chooses a random entry from a table
because this uses math.random, it cannot be used outside of events
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<table>
</li>
<li><span class="parameter">key</span>
<boolean> to indicate whether to return the key or value
</li>
</ul>
<h3>Returns:</h3>
<ol>
<any> a random element of table t
</ol>
</dd>
<dt>
<a name = "get_random_weighted"></a>
<strong>get_random_weighted (weight_table, item_index, weight_index)</strong>
</dt>
<dd>
Chooses a random entry from a weighted table
because this uses math.random, it cannot be used outside of events
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">weight_table</span>
<table> of tables with items and their weights
</li>
<li><span class="parameter">item_index</span>
<number> of the index of items, defaults to 1
</li>
<li><span class="parameter">weight_index</span>
<number> of the index of the weights, defaults to 2
</li>
</ul>
<h3>Returns:</h3>
<ol>
<any> table element
</ol>
<h3>See also:</h3>
<ul>
</ul>
</dd>
<dt>
<a name = "shuffle_table"></a>
<strong>shuffle_table (t)</strong>
</dt>
<dd>
Creates a fisher-yates shuffle of a sequential number-indexed table
because this uses math.random, it cannot be used outside of events if no rng is supplied
from: http://www.sdknews.com/cross-platform/corona/tutorial-how-to-shuffle-table-items
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<table> to shuffle
</li>
</ul>
</dd>
<dt>
<a name = "clear_table"></a>
<strong>clear_table (t, array)</strong>
</dt>
<dd>
Clears all existing entries in a table
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<table> to clear
</li>
<li><span class="parameter">array</span>
<boolean> to indicate whether the table is an array or not
</li>
</ul>
</dd>
</dl>
<h2><a name="Fields"></a>Fields</h2>
<dl class="function">
<dt>
<a name = "inspect"></a>
<strong>inspect</strong>
</dt>
<dd>
Similar to serpent.block, returns a string with a pretty representation of a table.
Notice: This method is not appropriate for saving/restoring tables. It is meant to be used by the programmer mainly while debugging a program.
depth sets the maximum depth that will be printed out. When the max depth is reached, inspect will stop parsing tables and just return {...}
process is a function which allow altering the passed object before transforming it into a string.
A typical way to use it would be to remove certain values so that they don't appear at all.
return <string> the prettied table
<ul>
<li><span class="parameter">table</span>
<table> the table to serialize
</li>
<li><span class="parameter">options</span>
<table> options are depth, newline, indent, process
</li>
</ul>
</dd>
<dt>
<a name = "size"></a>
<strong>size</strong>
</dt>
<dd>
Takes a table and returns the number of entries in the table. (Slower than #table, faster than iterating via pairs)
</dd>
<dt>
<a name = "deep_copy"></a>
<strong>deep_copy</strong>
</dt>
<dd>
Creates a deepcopy of a table. Metatables and LuaObjects inside the table are shallow copies.
Shallow copies meaning it copies the reference to the object instead of the object itself.
<ul>
<li><span class="parameter">object</span>
<table> the object to copy
</li>
</ul>
</dd>
<dt>
<a name = "merge"></a>
<strong>merge</strong>
</dt>
<dd>
Merges multiple tables. Tables later in the list will overwrite entries from tables earlier in the list.
Ex. merge({{1, 2, 3}, {[2] = 0}, {[3] = 0}}) will return {1, 0, 0}
<ul>
<li><span class="parameter">tables</span>
<table> takes a table of tables to merge
</li>
</ul>
</dd>
<dt>
<a name = "equals"></a>
<strong>equals</strong>
</dt>
<dd>
Determines if two tables are structurally equal.
Notice: tables that are LuaObjects or contain LuaObjects won't be compared correctly, use == operator for LuaObjects
<ul>
<li><span class="parameter">tbl1</span>
<table>
</li>
<li><span class="parameter">tbl2</span>
<table>
</li>
</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.3</a></i>
<i style="float:right;">Last updated 2019-05-29 22:22:59 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>