From 798a445643df6d2ba9355f8e25bc78e5713c588f Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sun, 17 Jan 2021 14:25:20 +0100 Subject: [PATCH] Remove or rename unused arguments and loop variables This is a style-only change. --- worldedit/primitives.lua | 10 ++++---- worldedit/serialization.lua | 6 ++--- worldedit_brush/init.lua | 2 +- worldedit_commands/cuboid.lua | 2 +- worldedit_commands/init.lua | 42 ++++++++++++++++----------------- worldedit_commands/mark.lua | 18 +++++++------- worldedit_commands/wand.lua | 2 +- worldedit_gui/functionality.lua | 2 +- worldedit_gui/init.lua | 12 +++++----- 9 files changed, 48 insertions(+), 48 deletions(-) diff --git a/worldedit/primitives.lua b/worldedit/primitives.lua index 10832e5..54f4fd0 100644 --- a/worldedit/primitives.lua +++ b/worldedit/primitives.lua @@ -278,7 +278,7 @@ function worldedit.spiral(pos, length, height, spacer, node_name) -- Add first column local count = height local column = i - for y = 1, height do + for _ = 1, height do data[column] = node_id column = column + stride.y end @@ -296,12 +296,12 @@ function worldedit.spiral(pos, length, height, spacer, node_name) segment_length = segment_length + spacer end -- Fill segment - for index = 1, segment_length do + for _ = 1, segment_length do -- Move along the direction of the segment i = i + stride_axis * sign local column = i -- Add column - for y = 1, height do + for _ = 1, height do data[column] = node_id column = column + stride.y end @@ -312,11 +312,11 @@ function worldedit.spiral(pos, length, height, spacer, node_name) -- Add shorter final segment sign = -sign - for index = 1, segment_length do + for _ = 1, segment_length do i = i + stride_axis * sign local column = i -- Add column - for y = 1, height do + for _ = 1, height do data[column] = node_id column = column + stride.y end diff --git a/worldedit/serialization.lua b/worldedit/serialization.lua index 400279e..8517e69 100644 --- a/worldedit/serialization.lua +++ b/worldedit/serialization.lua @@ -177,7 +177,7 @@ local function load_schematic(value) nodes = tables[1] if version == 1 then --original flat table format - for i, entry in ipairs(nodes) do + for _, entry in ipairs(nodes) do local pos = entry[1] entry.x, entry.y, entry.z = pos.x, pos.y, pos.z entry[1] = nil @@ -226,7 +226,7 @@ function worldedit.allocate_with_nodes(origin_pos, nodes) local pos1x, pos1y, pos1z = huge, huge, huge local pos2x, pos2y, pos2z = -huge, -huge, -huge local origin_x, origin_y, origin_z = origin_pos.x, origin_pos.y, origin_pos.z - for i, entry in ipairs(nodes) do + for _, entry in ipairs(nodes) do local x, y, z = origin_x + entry.x, origin_y + entry.y, origin_z + entry.z if x < pos1x then pos1x = x end if y < pos1y then pos1y = y end @@ -252,7 +252,7 @@ function worldedit.deserialize(origin_pos, value) local origin_x, origin_y, origin_z = origin_pos.x, origin_pos.y, origin_pos.z local count = 0 local add_node, get_meta = minetest.add_node, minetest.get_meta - for i, entry in ipairs(nodes) do + for _, entry in ipairs(nodes) do entry.x, entry.y, entry.z = origin_x + entry.x, origin_y + entry.y, origin_z + entry.z -- Entry acts as both position and node add_node(entry, entry) diff --git a/worldedit_brush/init.lua b/worldedit_brush/init.lua index 56b8280..a4abb6b 100644 --- a/worldedit_brush/init.lua +++ b/worldedit_brush/init.lua @@ -65,7 +65,7 @@ minetest.register_tool(":worldedit:brush", { inventory_image = "worldedit_brush.png", stack_max = 1, -- no need to stack these (metadata prevents this anyway) range = 0, - on_use = function(itemstack, placer, pointed_thing) + on_use = function(itemstack, placer) brush_on_use(itemstack, placer) return itemstack -- nothing consumed, nothing changed end, diff --git a/worldedit_commands/cuboid.lua b/worldedit_commands/cuboid.lua index 93e45fa..eb3f327 100644 --- a/worldedit_commands/cuboid.lua +++ b/worldedit_commands/cuboid.lua @@ -239,7 +239,7 @@ worldedit.register_command("cubeapply", { end return true, sidex, sidey, sidez, cmd, parsed end, - nodes_needed = function(name, sidex, sidey, sidez, cmd, parsed) + nodes_needed = function(_, sidex, sidey, sidez) -- its not possible to defer to the target command at this point return sidex * sidey * sidez end, diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 379370d..bf9fc45 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -64,7 +64,7 @@ end -- def = { -- privs = {}, -- Privileges needed -- params = "", -- Human readable parameter list (optional) --- -- setting params = "" will automatically provide a parse() if not given +-- -- setting params = "" will automatically provide a parse() if not given -- description = "", -- Description -- require_pos = 0, -- Number of positions required to be set (optional) -- parse = function(param) @@ -88,7 +88,7 @@ function worldedit.register_command(name, def) def.require_pos = def.require_pos or 0 assert(def.require_pos >= 0 and def.require_pos < 3) if def.params == "" and not def.parse then - def.parse = function(param) return true end + def.parse = function() return true end else assert(def.parse) end @@ -503,7 +503,7 @@ worldedit.register_command("fixedpos", { end, }) -minetest.register_on_punchnode(function(pos, node, puncher) +minetest.register_on_punchnode(function(pos, _, puncher) local name = puncher:get_player_name() if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position if worldedit.set_pos[name] == "pos1" then --setting position 1 @@ -612,7 +612,7 @@ worldedit.register_command("mix", { for nodename in param:gmatch("[^%s]+") do if tonumber(nodename) ~= nil and #nodes > 0 then local last_node = nodes[#nodes] - for i = 1, tonumber(nodename) do + for _ = 1, tonumber(nodename) do nodes[#nodes + 1] = last_node end else @@ -698,7 +698,7 @@ worldedit.register_command("hollowcube", { privs = {worldedit=true}, require_pos = 1, parse = check_cube, - nodes_needed = function(name, w, h, l, node) + nodes_needed = function(_, w, h, l) return w * h * l end, func = function(name, w, h, l, node) @@ -713,7 +713,7 @@ worldedit.register_command("cube", { privs = {worldedit=true}, require_pos = 1, parse = check_cube, - nodes_needed = function(name, w, h, l, node) + nodes_needed = function(_, w, h, l) return w * h * l end, func = function(name, w, h, l, node) @@ -740,7 +740,7 @@ worldedit.register_command("hollowsphere", { privs = {worldedit=true}, require_pos = 1, parse = check_sphere, - nodes_needed = function(name, radius, node) + nodes_needed = function(_, radius) return math.ceil((4 * math.pi * (radius ^ 3)) / 3) --volume of sphere end, func = function(name, radius, node) @@ -755,7 +755,7 @@ worldedit.register_command("sphere", { privs = {worldedit=true}, require_pos = 1, parse = check_sphere, - nodes_needed = function(name, radius, node) + nodes_needed = function(_, radius) return math.ceil((4 * math.pi * (radius ^ 3)) / 3) --volume of sphere end, func = function(name, radius, node) @@ -782,7 +782,7 @@ worldedit.register_command("hollowdome", { privs = {worldedit=true}, require_pos = 1, parse = check_dome, - nodes_needed = function(name, radius, node) + nodes_needed = function(_, radius) return math.ceil((2 * math.pi * (radius ^ 3)) / 3) --volume of dome end, func = function(name, radius, node) @@ -797,7 +797,7 @@ worldedit.register_command("dome", { privs = {worldedit=true}, require_pos = 1, parse = check_dome, - nodes_needed = function(name, radius, node) + nodes_needed = function(_, radius) return math.ceil((2 * math.pi * (radius ^ 3)) / 3) --volume of dome end, func = function(name, radius, node) @@ -830,7 +830,7 @@ worldedit.register_command("hollowcylinder", { privs = {worldedit=true}, require_pos = 1, parse = check_cylinder, - nodes_needed = function(name, axis, length, radius1, radius2, node) + nodes_needed = function(_, _, length, radius1, radius2) local radius = math.max(radius1, radius2) return math.ceil(math.pi * (radius ^ 2) * length) end, @@ -851,7 +851,7 @@ worldedit.register_command("cylinder", { privs = {worldedit=true}, require_pos = 1, parse = check_cylinder, - nodes_needed = function(name, axis, length, radius1, radius2, node) + nodes_needed = function(_, _, length, radius1, radius2) local radius = math.max(radius1, radius2) return math.ceil(math.pi * (radius ^ 2) * length) end, @@ -877,14 +877,14 @@ local check_pyramid = function(param) end return true, axis, tonumber(height), node end - + worldedit.register_command("hollowpyramid", { params = "x/y/z/? ", description = "Add hollow pyramid centered at WorldEdit position 1 along the given axis with height , composed of ", privs = {worldedit=true}, require_pos = 1, parse = check_pyramid, - nodes_needed = function(name, axis, height, node) + nodes_needed = function(_, _, height) return math.ceil(((height * 2 + 1) ^ 2) * height / 3) end, func = function(name, axis, height, node) @@ -904,7 +904,7 @@ worldedit.register_command("pyramid", { privs = {worldedit=true}, require_pos = 1, parse = check_pyramid, - nodes_needed = function(name, axis, height, node) + nodes_needed = function(_, _, height) return math.ceil(((height * 2 + 1) ^ 2) * height / 3) end, func = function(name, axis, height, node) @@ -934,7 +934,7 @@ worldedit.register_command("spiral", { end return true, tonumber(length), tonumber(height), tonumber(space), node end, - nodes_needed = function(name, length, height, space, node) + nodes_needed = function(_, length, height, space) return (length + space) * height -- TODO: this is not the upper bound end, func = function(name, length, height, space, node) @@ -955,7 +955,7 @@ worldedit.register_command("copy", { end return true, axis, tonumber(amount) end, - nodes_needed = function(name, axis, amount) + nodes_needed = function(name) return check_region(name) * 2 end, func = function(name, axis, amount) @@ -982,7 +982,7 @@ worldedit.register_command("move", { end return true, axis, tonumber(amount) end, - nodes_needed = function(name, axis, amount) + nodes_needed = function(name) return check_region(name) * 2 end, func = function(name, axis, amount) @@ -1014,7 +1014,7 @@ worldedit.register_command("stack", { end return true, axis, tonumber(repetitions) end, - nodes_needed = function(name, axis, repetitions) + nodes_needed = function(name, _, repetitions) return check_region(name) * math.abs(repetitions) end, func = function(name, axis, repetitions) @@ -1049,7 +1049,7 @@ worldedit.register_command("stack2", { return true, tonumber(repetitions), vector.new(tonumber(x), tonumber(y), tonumber(z)) end, - nodes_needed = function(name, repetitions, offset) + nodes_needed = function(name, repetitions) return check_region(name) * repetitions end, func = function(name, repetitions, offset) @@ -1629,7 +1629,7 @@ worldedit.register_command("mtschemprob", { if problist == nil then return end - for k,v in pairs(problist) do + for _,v in pairs(problist) do local prob = math.floor(((v.prob / 256) * 100) * 100 + 0.5) / 100 text = text .. minetest.pos_to_string(v.pos) .. ": " .. prob .. "% | " end diff --git a/worldedit_commands/mark.lua b/worldedit_commands/mark.lua index a195280..d43e8fc 100644 --- a/worldedit_commands/mark.lua +++ b/worldedit_commands/mark.lua @@ -134,17 +134,17 @@ minetest.register_entity(":worldedit:pos1", { physical = false, static_save = false, }, - on_activate = function(self, staticdata, dtime_s) + on_activate = function(self, staticdata) if staticdata ~= init_sentinel then -- we were loaded from before static_save = false was added self.object:remove() end end, - on_punch = function(self, hitter) + on_punch = function(self) self.object:remove() worldedit.marker1[self.player_name] = nil end, - on_blast = function(self, damage) + on_blast = function() return false, false, {} -- don't damage or knockback end, }) @@ -160,17 +160,17 @@ minetest.register_entity(":worldedit:pos2", { physical = false, static_save = false, }, - on_activate = function(self, staticdata, dtime_s) + on_activate = function(self, staticdata) if staticdata ~= init_sentinel then -- we were loaded from before static_save = false was added self.object:remove() end end, - on_punch = function(self, hitter) + on_punch = function(self) self.object:remove() worldedit.marker2[self.player_name] = nil end, - on_blast = function(self, damage) + on_blast = function() return false, false, {} -- don't damage or knockback end, }) @@ -183,13 +183,13 @@ minetest.register_entity(":worldedit:region_cube", { physical = false, static_save = false, }, - on_activate = function(self, staticdata, dtime_s) + on_activate = function(self, staticdata) if staticdata ~= init_sentinel then -- we were loaded from before static_save = false was added self.object:remove() end end, - on_punch = function(self, hitter) + on_punch = function(self) local markers = worldedit.marker_region[self.player_name] if not markers then return @@ -199,7 +199,7 @@ minetest.register_entity(":worldedit:region_cube", { end worldedit.marker_region[self.player_name] = nil end, - on_blast = function(self, damage) + on_blast = function() return false, false, {} -- don't damage or knockback end, }) diff --git a/worldedit_commands/wand.lua b/worldedit_commands/wand.lua index faa77ff..37b9f31 100644 --- a/worldedit_commands/wand.lua +++ b/worldedit_commands/wand.lua @@ -14,7 +14,7 @@ minetest.register_tool(":worldedit:wand", { stack_max = 1, -- there is no need to have more than one liquids_pointable = true, -- ground with only water on can be selected as well - on_use = function(itemstack, placer, pointed_thing) + on_use = function(_, placer, pointed_thing) if placer == nil or pointed_thing == nil then return end local name = placer:get_player_name() if pointed_thing.type == "node" then diff --git a/worldedit_gui/functionality.lua b/worldedit_gui/functionality.lua index 6279d8a..22b47c3 100644 --- a/worldedit_gui/functionality.lua +++ b/worldedit_gui/functionality.lua @@ -41,7 +41,7 @@ setmetatable(angle_values, {__index = function () return 90 end}) -- given multiple sets of privileges, produces a single set of privs that would have the same effect as requiring all of them at the same time local combine_privs = function(...) local result = {} - for i, privs in ipairs({...}) do + for _, privs in ipairs({...}) do for name, value in pairs(privs) do if result[name] ~= nil and result[name] ~= value then --the priv must be both true and false, which can never happen return {__fake_priv_that_nobody_has__=true} --privilege table that can never be satisfied diff --git a/worldedit_gui/init.lua b/worldedit_gui/init.lua index 1fae1c8..0275ca5 100644 --- a/worldedit_gui/init.lua +++ b/worldedit_gui/init.lua @@ -85,7 +85,7 @@ if minetest.global_exists("unified_inventory") then -- unified inventory install end, }) - minetest.register_on_player_receive_fields(function(player, formname, fields) + minetest.register_on_player_receive_fields(function(player, _, fields) local name = player:get_player_name() if fields.worldedit_gui then --main page worldedit.show_page(name, "worldedit_gui") @@ -116,7 +116,7 @@ elseif minetest.global_exists("inventory_plus") then -- inventory++ installed --show the form when the button is pressed and hide it when done local gui_player_formspecs = {} - minetest.register_on_player_receive_fields(function(player, formname, fields) + minetest.register_on_player_receive_fields(function(player, _, fields) local name = player:get_player_name() if fields.worldedit_gui then --main page gui_player_formspecs[name] = player:get_inventory_formspec() @@ -158,7 +158,7 @@ elseif minetest.global_exists("smart_inventory") then -- smart_inventory install codebox:set_we_formspec("worldedit_gui") -- process input (the back button) - state:onInput(function(state, fields, player) + state:onInput(function(state, fields) if fields.worldedit_gui then --main page state:get("code"):set_we_formspec("worldedit_gui") elseif fields.worldedit_gui_exit then --return to original page @@ -198,7 +198,7 @@ elseif minetest.global_exists("sfinv") then -- sfinv installed }) --show the form when the button is pressed and hide it when done - minetest.register_on_player_receive_fields(function(player, formname, fields) + minetest.register_on_player_receive_fields(function(player, _, fields) if fields.worldedit_gui then --main page worldedit.show_page(player:get_player_name(), "worldedit_gui") return true @@ -228,12 +228,12 @@ end worldedit.register_gui_function("worldedit_gui", { name = "WorldEdit GUI", privs = {interact=true}, - get_formspec = function(name) + get_formspec = function() --create a form with all the buttons arranged in a grid local buttons, x, y, index = {}, 0, 1, 0 local width, height = 3, 0.8 local columns = 5 - for i, identifier in pairs(identifiers) do + for _, identifier in pairs(identifiers) do if identifier ~= "worldedit_gui" then local entry = worldedit.pages[identifier] table.insert(buttons, string.format((entry.get_formspec and "button" or "button_exit") ..