Add: Difference between revisions
Jump to navigation
Jump to search
imported>Felice Enellen m (oops) |
imported>Felice Enellen m (double oops) |
||
| Line 37: | Line 37: | ||
* <code>[[Foreach|foreach()]]</code> | * <code>[[Foreach|foreach()]]</code> | ||
* <code>[[Pairs|pairs()]]</code> | * <code>[[Pairs|pairs()]]</code> | ||
* <code>[[ | * <code>[[IPairs|ipairs()]]</code> | ||
[[Category:Reference]] | [[Category:Reference]] | ||
[[Category:API]] | [[Category:API]] | ||
Revision as of 11:47, 29 June 2021
add( table, value, [index] )
- Adds a element to the end of a sequence in a table.
- table
-
- The table.
- value
-
- The value to add.
- index
-
- The index for the value to be inserted.
The add() function adds an element to a sequence in a table.
If an index is not supplied, it is assumed to be #table+1 and the value is appended to the end of the table.
The add() function returns the object being added. You can ignore this return value if you don't need it.
A stack can be easily emulated by using add(s,v) to push and v=deli(s) to pop.
Examples
t = {1, 5}
add(t, 7) -- t = {1, 5, 7}
add(t, 9) -- t = {1, 5, 7, 9}
add(t, 3, 2) -- t = {1, 3, 5, 7, 9}
-- used to create and keep track of all players
players = {}
function new_player(pad_index, name)
return add(players, {pad_index, name})
end