If you want them inserted in the correct order, @starmaq solution is correct but you need to use the ipairs iterator:
local Table1 = {1,2,3}
local Table2 = {4,5,6}
--Moving all values from Table 2 to Table 1
for i, v in ipairs(Table2 ) do
table.insert(Table1, v)
end
--Now all the values will be in the first table
for i,v in ipairs (Table1) do
print(v)
end
This supports multiple tables if you didn’t want to keep repeating yourself
local function combine(...)
local tables = {...}
local totalContentCount = 0
for _,t in pairs(tables) do
totalContentCount += #t
end
local combined = table.create(totalContentCount)
for _,t in pairs(tables) do
table.move(t, 1, #t, #combined, combined)
end
return combined
end
-- usage example
local exampleTableOne = {'bool', 'string', 'number', 'instance'}
local exampleTableTwo = {'One', 1, 14, 43, "ABC", "D"}
local exampleTableThree = {14 % 2 == 0, ":)"}
local result = combine(exampleTableOne, exampleTableTwo, exampleTableThree)
print(result)
prints 3 when it “should” print 4. Only the first value from each table.unpack expression before the last is taken, so the resulting table has 1, 3 and 4. This is explained in the manual
Both function calls and vararg expressions can result in multiple values. If an expression is used as a statement (only possible for function calls (see §2.4.6)), then its return list is adjusted to zero elements, thus discarding all returned values. If an expression is used as the last (or the only) element of a list of expressions, then no adjustment is made (unless the call is enclosed in parentheses). In all other contexts, Lua adjusts the result list to one element, discarding all values except the first one.
That section of the manual also has lots of examples which I recommend checking out