> To write an efficient pure Lua routine is possible, but quite challenging.
an O( n * log( n ) ) one:
"""
function _concat( t, p, n )
if n > 1 then
local n2 = n // 2
return _concat( t, p, n2 ) .. _concat( t, p + n2, n - n2 )
end
return t[ p ]
end
function concat( tbl )
return _concat( tbl, 1, #tbl )
end
"""
For lua < 5.3 use math.floor( n / 2) or math.ceil, or round or whatever, it doesn't matter.