Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerkiz committed Feb 5, 2025
1 parent 8bc3420 commit b171903
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 6 additions & 2 deletions utils/gui/poll.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--luacheck: ignore 143
local Gui = require 'utils.gui'
local Global = require 'utils.global'
local Event = require 'utils.event'
Expand All @@ -9,6 +10,8 @@ local Math = require 'utils.math.math'
local Public = {}

local insert = table.insert
local contains = table.contains
local remove_element = table.remove_element

local default_poll_duration = 300 * 60 -- in ticks
local duration_max = 3600 -- in seconds
Expand Down Expand Up @@ -1088,7 +1091,7 @@ Gui.on_click(
for i, p in pairs(polls) do
if p == poll then
table.remove(polls, i)
table.remove_element(running_polls, p)
remove_element(running_polls, p)
removed_index = i
break
end
Expand Down Expand Up @@ -1214,7 +1217,8 @@ Gui.on_click(
insert(polls, poll)
insert(running_polls, poll)
poll_index = #polls
elseif not table.contains(running_polls, poll) then
---@diagnostic disable-next-line: undefined-global
elseif not contains(running_polls, poll) then
insert(running_polls, poll)
end

Expand Down
17 changes: 9 additions & 8 deletions utils/list_utils.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
--luacheck: ignore
local function assert_argument_valid(a, arg_type)
arg_type = arg_type or 'table'
Expand All @@ -6,7 +7,7 @@ local function assert_argument_valid(a, arg_type)
end
end

table.remove_element = function(t, element)
table.remove_element = function (t, element)
assert_argument_valid(t)
for k, v in pairs(t) do
if v == element then
Expand All @@ -16,7 +17,7 @@ table.remove_element = function(t, element)
end
end

table.add_all = function(t1, t2)
table.add_all = function (t1, t2)
assert_argument_valid(t1)
assert_argument_valid(t2)
for k, v in pairs(t2) do
Expand All @@ -28,7 +29,7 @@ table.add_all = function(t1, t2)
end
end

table.size = function(t)
table.size = function (t)
assert_argument_valid(t)
local size = 0
for _, _ in pairs(t) do
Expand All @@ -37,7 +38,7 @@ table.size = function(t)
return size
end

table.index_of = function(t, e)
table.index_of = function (t, e)
assert_argument_valid(t)
local i = 1
for _, v in pairs(t) do
Expand All @@ -49,12 +50,12 @@ table.index_of = function(t, e)
return -1
end

table.contains = function(t, e)
table.contains = function (t, e)
assert_argument_valid(t)
return table.index_of(t, e) > -1
end

table.set = function(t, index, element)
table.set = function (t, index, element)
assert_argument_valid(t)
assert_argument_valid(index, 'number')
local i = 1
Expand All @@ -68,7 +69,7 @@ table.set = function(t, index, element)
error('Index out of bounds', 2)
end

table.get = function(t, index)
table.get = function (t, index)
assert_argument_valid(t)
assert_argument_valid(index, 'number')
local i = 1
Expand Down Expand Up @@ -97,7 +98,7 @@ end
game.print("value found at index: " .. index)
end
]]
table.binary_search = function(t, target)
table.binary_search = function (t, target)
--For some reason bit32.bnot doesn't return negative numbers so I'm using ~x = -1 - x instead.
assert_argument_valid(t)
assert_argument_valid(target, 'number')
Expand Down
1 change: 1 addition & 0 deletions utils/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ local index_of = table.index_of
---@param t table
---@param e any #table element
---@return boolean #boolean indicating success
---@diagnostic disable-next-line: duplicate-set-field access-global-from-locals
function table.contains(t, e)
return index_of(t, e) and true or false
end
Expand Down

0 comments on commit b171903

Please sign in to comment.