Lua 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 wherea1is the source table anda2is the destination table.fmeans from (First index withina1).emeans end (Last index withina1).tmeans 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
Table2is 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.
Learn Lua on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
- Beginner Friendly.4 hours