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 — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Lua Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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.
Frequently asked questions
Is the “table.concat and table.move” lesson free?
Yes — the full text of “table.concat and table.move” is free to read here on the web, and the Lua Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Lua Academy course, upgrade to CoddyKit PRO.
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; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
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