table.concat and table.move
Efficiently join arrays and copy table slices with built-in functions.
table.concat and table.move is a free Lua Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Lua Academy learning path, and your progress syncs across the web and the CoddyKit app. The Lua Academy course includes 4 lessons in total.
table.concat Basics
table.concat(t, sep, i, j) joins array elements into a string. sep defaults to "".
Simple Join
Join an array of strings with a separator.
local fruits = {"apple", "banana", "cherry"}
print(table.concat(fruits, ", ")) -- apple, banana, cherryPartial Join with i and j
Specify start and end indices to join a slice of the array.
local t = {"a", "b", "c", "d", "e"}
print(table.concat(t, "-", 2, 4)) -- b-c-dNumbers in table.concat
Elements must be strings or numbers; other types cause an error. Convert with tostring first.
local nums = {1, 2, 3}
print(table.concat(nums, " + ")) -- 1 + 2 + 3table.move Introduction
table.move(a1, f, e, t, a2) copies elements from table a1 (indices f..e) into table a2 starting at index t.
Copying a Slice
Copy elements 2 through 4 of one table into another.
local src = {10, 20, 30, 40, 50}
local dst = {}
table.move(src, 2, 4, 1, dst)
print(table.concat(dst, ", ")) -- 20, 30, 40In-Place Shift
Use table.move with the same source and destination to shift elements within a table.
local t = {1, 2, 3, 4, 5}
table.move(t, 2, 5, 1) -- shift left by 1
t[5] = nilAppending a Slice
Append a slice of one table to the end of another efficiently.
local base = {"x", "y"}
local extra = {"a", "b", "c"}
table.move(extra, 1, #extra, #base + 1, base)
print(table.concat(base, ", "))Cloning a Table with table.move
A shallow clone can be made by moving the entire table into a fresh table.
local original = {1, 2, 3}
local clone = {}
table.move(original, 1, #original, 1, clone)Performance Benefit
table.move is implemented in C and is faster than a manual Lua loop for large slices, as it avoids interpreter overhead per element.
table.concat vs string.format
Use table.concat for joining arrays; use string.format for structured formatting of individual values.
table.move Question
What does table.move(src, 2, 4, 1, dst) do?
Recap: concat & move
table.concat joins array elements into a string. table.move efficiently copies table slices in C. Both are essential for high-performance table manipulation.
Learn Lua with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 40
- Lessons
- 159
Frequently Asked Questions
Is the “table.concat and table.move” lesson free?
Yes — any 3 lessons of the Lua Academy learning path, including “table.concat and table.move”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Lua Academy course includes 4 lessons in total.
What will I learn in “table.concat and table.move”?
Efficiently join arrays and copy table slices with built-in functions. You practise Lua Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Lua Academy?
No prior experience is required. Lua Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “table.concat and table.move” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Lua Academy lesson?
Yes. Every Lua Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- table.sort with Comparators
- table.concat and table.move
- Deep Copy and Shallow Copy
- Transforming Tables: map, filter, reduce