Software /
code /
verse
Comparison
libs/table.lua @ 483:33d566513eb0
libs/table: Add table.move
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 17 Mar 2023 17:09:00 +0000 |
parent | 439:6fc73ad6b1d2 |
comparison
equal
deleted
inserted
replaced
482:4c4f3dd62c54 | 483:33d566513eb0 |
---|---|
1 return {pack = function(...) return {n = select("#", ...); ...} end; create = function() return {} end} | 1 return { |
2 pack = function(...) return {n = select("#", ...); ...} end; | |
3 create = function() return {} end; | |
4 move = function (a1, f, e, t, a2) | |
5 a2 = a2 or a1; | |
6 if e >= f then | |
7 local n = (e - f) + 1; | |
8 if t > e or t <= f or a1 ~= a2 then | |
9 for i = 0, n-1 do | |
10 a2[t+i] = a1[f+i]; | |
11 end | |
12 else | |
13 for i = n-1, 0, -1 do | |
14 a2[t+i] = a1[f+i]; | |
15 end | |
16 end | |
17 end | |
18 return a2; | |
19 end; | |
20 } |