move()
Published Oct 3, 2023
Contribute to Docs
The .move()
function copies the specified indicesā values from the source table into the provided starting index of the destination table.
Syntax
table.move(a1, f, e, t, a2)
.move()
function expects five arguments wherea1
is the source table anda2
is the destination table.f
means from (First index withina1
).e
means end (Last index withina1
).t
means to (First index withina2
).
Example
Consider the following tables:
local Table1 = {"š", "š", "š", "š", "š" }local Table2 = {"š", "š"}table.move(Table1, 1, #Table1, 3, Table2)print(table.unpack(Table2))
In this example, the elements in Table1
have been copied to Table2
using the .move()
function. Starting from index 1 in Table1
until the end and then copying them in sequence to Table2
starting from index 3.
The above code will result in:
ššššššš
Note: In Lua, indices start from 1; thus, the next available index in
Table2
is index 3.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.