Limit table.concat to part of an array.

start and finish The optional start and finish indexes choose which items are joined.

Concat Window

firstIndex
concat_window.lua
Replay: real traced execution (multi-file project)
local firstIndex = 2
local lastIndex = firstIndex + 1
local joined = table.concat({"red", "green", "blue", "gray"}, "-", firstIndex, lastIndex)
print("firstIndex=" .. firstIndex)
print("lastIndex=" .. lastIndex)
print("joined=" .. joined)
local firstIndex = 1
local lastIndex = firstIndex + 1
local joined = table.concat({"red", "green", "blue", "gray"}, "-", firstIndex, lastIndex)
print("firstIndex=" .. firstIndex)
print("lastIndex=" .. lastIndex)
print("joined=" .. joined)
local firstIndex = 3
local lastIndex = firstIndex + 1
local joined = table.concat({"red", "green", "blue", "gray"}, "-", firstIndex, lastIndex)
print("firstIndex=" .. firstIndex)
print("lastIndex=" .. lastIndex)
print("joined=" .. joined)
  1. firstIndex ← 2, lastIndex ← 3, joined ← green-blue

    1local firstIndex→ 2 = 2 --@firstIndex=1, 32local lastIndex→ 3 = firstIndex2 + 13local joined→ green-blue = table.concat({"red", "green", "blue", "gray"}, "-", firstIndex2, lastIndex3)4print("firstIndex=" .. firstIndex2)5print("lastIndex=" .. lastIndex3)6print("joined=" .. joinedgreen-blue)
    outputfirstIndex=2
    lastIndex=3
    joined=green-blue
  1. firstIndex ← 1, lastIndex ← 2, joined ← red-green

    1local firstIndex→ 1 = 12local lastIndex→ 2 = firstIndex1 + 13local joined→ red-green = table.concat({"red", "green", "blue", "gray"}, "-", firstIndex1, lastIndex2)4print("firstIndex=" .. firstIndex1)5print("lastIndex=" .. lastIndex2)6print("joined=" .. joinedred-green)
    outputfirstIndex=1
    lastIndex=2
    joined=red-green
  1. firstIndex ← 3, lastIndex ← 4, joined ← blue-gray

    1local firstIndex→ 3 = 32local lastIndex→ 4 = firstIndex3 + 13local joined→ blue-gray = table.concat({"red", "green", "blue", "gray"}, "-", firstIndex3, lastIndex4)4print("firstIndex=" .. firstIndex3)5print("lastIndex=" .. lastIndex4)6print("joined=" .. joinedblue-gray)
    outputfirstIndex=3
    lastIndex=4
    joined=blue-gray