Skip to content

Commit f3ea41d

Browse files
committed
fix(CommandExecutor): fix command dumping
- Fix command dumping using the `!list` command (and aliases) not updating the sorted list with newly added commands at runtime (ex: YimActions commands).
1 parent d952c28 commit f3ea41d

2 files changed

Lines changed: 32 additions & 34 deletions

File tree

SSV2/includes/lib/utils.lua

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -958,13 +958,11 @@ end
958958
---@param value string | number | integer | table
959959
function table.getduplicates(t, value)
960960
local count = 0
961-
962961
for _, v in ipairs(t) do
963962
if (value == v) then
964963
count = count + 1
965964
end
966965
end
967-
968966
return count
969967
end
970968

@@ -995,8 +993,10 @@ function table.removeduplicates(t, debug)
995993
return debug and t_result or t_clean
996994
end
997995

998-
---@param t table
996+
---@generic T : table
997+
---@param t T
999998
---@param seen? table
999+
---@return T
10001000
function table.copy(t, seen)
10011001
seen = seen or {}
10021002
if seen[t] then
@@ -1023,10 +1023,10 @@ end
10231023
---@param path string?
10241024
---@param seen table?
10251025
function table.merge(src, dest, path, seen)
1026+
if (src == dest) then return end
1027+
10261028
seen = seen or {}
1027-
if (seen[src]) then
1028-
return
1029-
end
1029+
if (seen[src]) then return end
10301030
seen[src] = true
10311031

10321032
for k, v in pairs(src) do
@@ -1039,24 +1039,21 @@ function table.merge(src, dest, path, seen)
10391039
end
10401040
end
10411041

1042-
---@param inTable table
1043-
---@param outTable table
1044-
function table.swap(inTable, outTable)
1045-
if (inTable == outTable) then
1046-
return
1047-
end
1042+
---@param t1 table
1043+
---@param t2 table
1044+
function table.swap(t1, t2)
1045+
if (t1 == t2) then return end
10481046

10491047
local temp = {}
1050-
1051-
for k, v in pairs(inTable) do
1052-
temp[k] = v
1053-
inTable[k] = nil
1048+
for k, v in pairs(t1) do
1049+
temp[k] = v
1050+
t1[k] = nil
10541051
end
10551052

1056-
for k, v in pairs(outTable) do
1057-
inTable[k] = v
1058-
outTable[k] = temp[k]
1059-
temp[k] = nil
1053+
for k, v in pairs(t2) do
1054+
t1[k] = v
1055+
t2[k] = temp[k]
1056+
temp[k] = nil
10601057
end
10611058
end
10621059

@@ -1065,7 +1062,7 @@ end
10651062
---@param src table
10661063
---@param seen? table
10671064
function table.overwrite(this, src, seen)
1068-
if (this == src) then return this end
1065+
if (this == src) then return end
10691066

10701067
seen = seen or {}
10711068
if (seen[src]) then return end
@@ -1089,37 +1086,37 @@ function table.overwrite(this, src, seen)
10891086
end
10901087
end
10911088

1092-
---@param a table
1093-
---@param b table
1089+
---@param t1 table
1090+
---@param t2 table
10941091
---@param seen? table
10951092
---@return boolean
1096-
function table.is_equal(a, b, seen)
1097-
if (a == b) then
1093+
function table.is_equal(t1, t2, seen)
1094+
if (t1 == t2) then
10981095
return true
10991096
end
11001097

1101-
if (type(a) ~= type(b)) then
1098+
if (type(t1) ~= type(t2)) then
11021099
return false
11031100
end
11041101

1105-
if (type(a) ~= "table") then
1102+
if (type(t1) ~= "table") then
11061103
return false
11071104
end
11081105

11091106
seen = seen or {}
1110-
if (seen[a] and seen[b]) then
1107+
if (seen[t1] and seen[t2]) then
11111108
return true
11121109
end
1113-
seen[a], seen[b] = true, true
1110+
seen[t1], seen[t2] = true, true
11141111

1115-
for k, v in pairs(a) do
1116-
if (not table.is_equal(v, b[k], seen)) then
1112+
for k, v in pairs(t1) do
1113+
if (not table.is_equal(v, t2[k], seen)) then
11171114
return false
11181115
end
11191116
end
11201117

1121-
for k in pairs(b) do
1122-
if (a[k] == nil) then
1118+
for k in pairs(t2) do
1119+
if (t1[k] == nil) then
11231120
return false
11241121
end
11251122
end

SSV2/includes/services/CommandExecutor.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ function CommandExecutor:GetDefaultCommands()
558558
return {
559559
["!list"] = {
560560
callback = function()
561-
if (not self.m_sorted_command_names) then
561+
-- We have several similar use cases so it's probably a good idea to add an OrderedMap struct
562+
if (not self.m_sorted_command_names or #self.m_sorted_command_names ~= table.getlen(self.m_commands)) then
562563
self.m_sorted_command_names = {}
563564
for name in pairs(self.m_commands) do
564565
table.insert(self.m_sorted_command_names, name)

0 commit comments

Comments
 (0)