Thanks all, there is the solution for Lua 5.1 (and 5.4)
if not table.move then
print ('used custom table.move')
-- thanks to index five
function table.move(a1,f,e,t,a2) -- a1, f, e, t [,a2]
-- Moves elements from the table a1 to the table a2,
-- performing the equivalent to the following multiple assignment:
-- a2[t],··· = a1[f],···,a1[e]. The default for a2 is a1.
-- The destination range can overlap with the source range.
-- The number of elements to be moved must fit in a Lua integer.
a2 = a2 or a1
if (a2 ~= a1) or (t < f) then -- use a2
for i = f, e do
a2[t+i-f] = a1[i]
end
elseif (t > f) then
for i = e, f, -1 do
a2[t+i-f] = a1[i]
end
end
return a2
end
end
table.unpack = table.unpack or unpack
function circularShift (tabl, shift)
local len = #tabl
local shifted = {}
table.move(tabl,len-shift,len,0,shifted)
table.move(tabl,1,len-shift,shift+1,shifted)
return shifted
end
local connections = {1, 1, 0, 1}
print (table.unpack(circularShift(connections, 0)))
print (table.unpack(circularShift(connections, 1)))
print (table.unpack(circularShift(connections, 2)))
print (table.unpack(circularShift(connections, 3)))
Result:
1 1 0 1
1 1 1 0
0 1 1 1
1 0 1 1
But the version of LMD is simpler and can accept left shifting too.
table.insert(connections, 1, table.remove(connections))and was not sure that it was a good solution