libs/table.lua

Wed, 21 Jun 2023 15:22:17 +0200

author
Kim Alvefur <zash@zash.se>
date
Wed, 21 Jun 2023 15:22:17 +0200
changeset 493
08e5c8637fea
parent 483
33d566513eb0
permissions
-rw-r--r--

squishy: Normalise Lua syntax

lua-format applied

Makes semi-automated merging with e.g. rockspec files easier.

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 }

mercurial