Annotate

libs/table.lua @ 506:3610196c5e83 default tip

Merge with Zash.
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Sat, 08 Jul 2023 02:17:52 +0700
parent 483:33d566513eb0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
483
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
1 return {
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
2 pack = function(...) return {n = select("#", ...); ...} end;
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
3 create = function() return {} end;
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
4 move = function (a1, f, e, t, a2)
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
5 a2 = a2 or a1;
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
6 if e >= f then
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
7 local n = (e - f) + 1;
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
8 if t > e or t <= f or a1 ~= a2 then
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
9 for i = 0, n-1 do
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
10 a2[t+i] = a1[f+i];
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
11 end
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
12 else
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
13 for i = n-1, 0, -1 do
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
14 a2[t+i] = a1[f+i];
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
15 end
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
16 end
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
17 end
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
18 return a2;
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
19 end;
33d566513eb0 libs/table: Add table.move
Matthew Wild <mwild1@gmail.com>
parents: 439
diff changeset
20 }