<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://pico8wiki.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=46.134.147.82</id>
	<title>Pico-8 Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://pico8wiki.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=46.134.147.82"/>
	<link rel="alternate" type="text/html" href="http://pico8wiki.com/index.php?title=Special:Contributions/46.134.147.82"/>
	<updated>2026-11-12T18:09:01Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.1</generator>
	<entry>
		<id>http://pico8wiki.com/index.php?title=Add&amp;diff=13274</id>
		<title>Add</title>
		<link rel="alternate" type="text/html" href="http://pico8wiki.com/index.php?title=Add&amp;diff=13274"/>
		<updated>2023-10-22T19:38:17Z</updated>

		<summary type="html">&lt;p&gt;46.134.147.82: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ApiReference&lt;br /&gt;
|name=add&lt;br /&gt;
|shortdesc=Adds an element to the end of a sequence in a table.&lt;br /&gt;
|table||The table.&lt;br /&gt;
|value||The value to add.&lt;br /&gt;
|index|optional|The index for the value to be inserted.&lt;br /&gt;
|result=The &amp;lt;var&amp;gt;value&amp;lt;/var&amp;gt; that was passed in.&lt;br /&gt;
}}&lt;br /&gt;
The &amp;lt;code&amp;gt;add()&amp;lt;/code&amp;gt; function adds an element to a sequence in a table.&lt;br /&gt;
&lt;br /&gt;
If an &amp;lt;var&amp;gt;index&amp;lt;/var&amp;gt; is not supplied, it is assumed to be &amp;lt;code&amp;gt;#table+1&amp;lt;/code&amp;gt; and the value is appended to the end of the table.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;add()&amp;lt;/code&amp;gt; function returns the object being added. You can ignore this return value if you don&#039;t need it.&lt;br /&gt;
&lt;br /&gt;
A stack can be easily emulated by using &amp;lt;code&amp;gt;add(s,v)&amp;lt;/code&amp;gt; to push and &amp;lt;code&amp;gt;[[Deli|v=deli(s)]]&amp;lt;/code&amp;gt; to pop.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
t = {1, 5}&lt;br /&gt;
add(t, 7)  -- t = {1, 5, 7}&lt;br /&gt;
add(t, 9)  -- t = {1, 5, 7, 9}&lt;br /&gt;
add(t, 3, 2)  -- t = {1, 3, 5, 7, 9}&lt;br /&gt;
&lt;br /&gt;
-- used to create and keep track of all players&lt;br /&gt;
players = {}&lt;br /&gt;
function new_player(pad_index, name)&lt;br /&gt;
  return add(players, {pad_index, name})&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Lua]]&lt;br /&gt;
* [[Tables]]&lt;br /&gt;
* &amp;lt;code&amp;gt;[[All|all()]]&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;[[Del|del()]]&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;[[Deli|deli()]]&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;[[Foreach|foreach()]]&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;[[Pairs|pairs()]]&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;[[IPairs|ipairs()]]&amp;lt;/code&amp;gt;&lt;br /&gt;
[[Category:Reference]]&lt;br /&gt;
[[Category:API]]&lt;/div&gt;</summary>
		<author><name>46.134.147.82</name></author>
	</entry>
</feed>