From 25aaab20dea926738b8d5aa5ab05ea0074c866d1 Mon Sep 17 00:00:00 2001 From: Panquesito7 Date: Sat, 8 Feb 2020 01:27:57 -0600 Subject: [PATCH] Remove ignore list and fix many warnings --- .luacheckrc | 10 ---------- worldedit/code.lua | 6 ++++-- worldedit/common.lua | 2 +- worldedit/compatibility.lua | 7 ++++++- worldedit/manipulations.lua | 34 +++++++++++++++++----------------- worldedit/serialization.lua | 3 +-- worldedit/visualization.lua | 2 +- worldedit_brush/init.lua | 2 +- worldedit_commands/init.lua | 15 ++++++++++----- worldedit_commands/mark.lua | 6 +++--- 10 files changed, 44 insertions(+), 43 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 7233ead..b89b672 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -2,16 +2,6 @@ unused_args = false allow_defined_top = true max_line_length = 999 -ignore = { - "pos1", "pos2", - "extent1", "extent2", - "header", "count", - - "err", "state", - "filename", "def", - "file", "name", -} - read_globals = { string = {fields = {"split", "trim"}}, table = {fields = {"copy", "getn"}}, diff --git a/worldedit/code.lua b/worldedit/code.lua index a939deb..0fbe9e3 100644 --- a/worldedit/code.lua +++ b/worldedit/code.lua @@ -8,7 +8,8 @@ function worldedit.lua(code) if not func then -- Syntax error return err end - local good, err = pcall(func) + local good = pcall(func) + err = pcall(func) if not good then -- Runtime error return err end @@ -37,7 +38,8 @@ function worldedit.luatransform(pos1, pos2, code) while pos.y <= pos2.y do pos.z = pos1.z while pos.z <= pos2.z do - local good, err = pcall(func, pos) + local good = pcall(func) + err = pcall(func, pos) if not good then -- Runtime error return err end diff --git a/worldedit/common.lua b/worldedit/common.lua index c62957f..e890d51 100644 --- a/worldedit/common.lua +++ b/worldedit/common.lua @@ -23,7 +23,7 @@ end --- Determines the volume of the region defined by positions `pos1` and `pos2`. -- @return The volume. function worldedit.volume(pos1, pos2) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) return (pos2.x - pos1.x + 1) * (pos2.y - pos1.y + 1) * (pos2.z - pos1.z + 1) diff --git a/worldedit/compatibility.lua b/worldedit/compatibility.lua index c989a05..f0c7bf2 100644 --- a/worldedit/compatibility.lua +++ b/worldedit/compatibility.lua @@ -26,8 +26,13 @@ end function worldedit.metaload(originpos, filename) deprecated("load") + + local file = io.open(filename, "wb") filename = minetest.get_worldpath() .. "/schems/" .. file .. ".wem" - local file, err = io.open(filename, "wb") + file = io.open(filename, "wb") + + local err = io.open(filename, "wb") + if err then return 0 end local data = file:read("*a") return worldedit.deserialize(originpos, data) diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index 5fde841..c503429 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -66,7 +66,7 @@ end -- When `inverse` is `true`, replaces all instances that are NOT `search_node`. -- @return The number of nodes replaced. function worldedit.replace(pos1, pos2, search_node, replace_node, inverse) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local manip, area = mh.init(pos1, pos2) local data = manip:get_data() @@ -150,7 +150,7 @@ end -- @param amount -- @return The number of nodes copied. function worldedit.copy(pos1, pos2, axis, amount) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) -- Decide if we need to copy stuff backwards (only applies to metadata) local backwards = amount > 0 and amount < (pos2[axis] - pos1[axis] + 1) @@ -167,7 +167,7 @@ end -- @param meta_backwards (not officially part of API) -- @return The number of nodes copied. function worldedit.copy2(pos1, pos2, off, meta_backwards) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local src_manip, src_area = mh.init(pos1, pos2) local src_stride = {x=1, y=src_area.ystride, z=src_area.zstride} @@ -252,7 +252,7 @@ end -- @param pos2 -- @return The number of nodes that had their meta deleted. function worldedit.delete_meta(pos1, pos2) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local meta_positions = minetest.find_nodes_with_meta(pos1, pos2) local get_meta = minetest.get_meta @@ -266,7 +266,7 @@ end --- Moves a region along `axis` by `amount` nodes. -- @return The number of nodes moved. function worldedit.move(pos1, pos2, axis, amount) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local dim = vector.add(vector.subtract(pos2, pos1), 1) local overlap = math.abs(amount) < dim[axis] @@ -315,7 +315,7 @@ end -- @param count -- @return The number of nodes stacked. function worldedit.stack(pos1, pos2, axis, count, finished) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local length = pos2[axis] - pos1[axis] + 1 if count < 0 then count = -count @@ -346,7 +346,7 @@ end -- @return The new scaled position 1. -- @return The new scaled position 2. function worldedit.stretch(pos1, pos2, stretch_x, stretch_y, stretch_z) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) -- Prepare schematic of large node local get_node, get_meta, place_schematic = minetest.get_node, @@ -418,18 +418,18 @@ end -- @return The new transposed position 1. -- @return The new transposed position 2. function worldedit.transpose(pos1, pos2, axis1, axis2) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local compare local extent1, extent2 = pos2[axis1] - pos1[axis1], pos2[axis2] - pos1[axis2] if extent1 > extent2 then - compare = function(extent1, extent2) - return extent1 > extent2 + compare = function(extent1_2, extent2_2) + return extent1_2 > extent2_2 end else - compare = function(extent1, extent2) - return extent1 < extent2 + compare = function(extent1_2, extent2_2) + return extent1_2 < extent2_2 end end @@ -451,7 +451,7 @@ function worldedit.transpose(pos1, pos2, axis1, axis2) while pos.y <= pos2.y do pos.z = pos1.z while pos.z <= pos2.z do - local extent1, extent2 = pos[axis1] - pos1[axis1], pos[axis2] - pos1[axis2] + extent1, extent2 = pos[axis1] - pos1[axis1], pos[axis2] - pos1[axis2] if compare(extent1, extent2) then -- Transpose only if below the diagonal local node1 = get_node(pos) local meta1 = get_meta(pos):to_table() @@ -478,7 +478,7 @@ end --- Flips a region along `axis`. -- @return The number of nodes flipped. function worldedit.flip(pos1, pos2, axis) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) worldedit.keep_loaded(pos1, pos2) @@ -523,7 +523,7 @@ end -- @return The new first position. -- @return The new second position. function worldedit.rotate(pos1, pos2, axis, angle) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local other1, other2 = worldedit.get_axis_others(axis) angle = angle % 360 @@ -551,7 +551,7 @@ end -- @param angle Angle in degrees (90 degree increments only). -- @return The number of nodes oriented. function worldedit.orient(pos1, pos2, angle) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local registered_nodes = minetest.registered_nodes local wallmounted = { @@ -621,7 +621,7 @@ end --- Attempts to fix the lighting in a region. -- @return The number of nodes updated. function worldedit.fixlight(pos1, pos2) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local vmanip = minetest.get_voxel_manip(pos1, pos2) vmanip:write_to_map() diff --git a/worldedit/serialization.lua b/worldedit/serialization.lua index c3793b2..5566a47 100644 --- a/worldedit/serialization.lua +++ b/worldedit/serialization.lua @@ -148,7 +148,7 @@ end --- Loads the schematic in `value` into a node list in the latest format. -- @return A node list in the latest format, or nil on failure. local function load_schematic(value) - local version, header, content = worldedit.read_header(value) + local version, _, content = worldedit.read_header(value) local nodes = {} if version == 1 or version == 2 then -- Original flat table format local tables = minetest.deserialize(content, true) @@ -240,7 +240,6 @@ function worldedit.deserialize(origin_pos, value) worldedit.keep_loaded(pos1, pos2) 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 entry.x, entry.y, entry.z = origin_x + entry.x, origin_y + entry.y, origin_z + entry.z diff --git a/worldedit/visualization.lua b/worldedit/visualization.lua index 326a6c1..04aac20 100644 --- a/worldedit/visualization.lua +++ b/worldedit/visualization.lua @@ -111,7 +111,7 @@ end -- by positions `pos1` and `pos2`. -- @return The number of nodes restored. function worldedit.restore(pos1, pos2) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) worldedit.keep_loaded(pos1, pos2) diff --git a/worldedit_brush/init.lua b/worldedit_brush/init.lua index 0c1ff95..f2aa5dc 100644 --- a/worldedit_brush/init.lua +++ b/worldedit_brush/init.lua @@ -43,7 +43,7 @@ local brush_on_use = function(itemstack, placer) -- this isn't really clean... local player_notify_old = worldedit.player_notify - worldedit.player_notify = function(name, msg) + worldedit.player_notify = function(player, msg) if string.match(msg, "^%d") then return end -- discard "1234 nodes added." return player_notify_old(name, msg) end diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 0028c60..c575a03 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -82,7 +82,7 @@ end -- end, -- } function worldedit.register_command(name, def) - local def = table.copy(def) + def = table.copy(def) assert(name and #name > 0) assert(def.privs) def.require_pos = def.require_pos or 0 @@ -1030,7 +1030,8 @@ worldedit.register_command("stretch", { end, func = function(name, stretchx, stretchy, stretchz) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] - local count, pos1, pos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz) + local count = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz) + pos1, pos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz) --reset markers to scaled positions worldedit.pos1[name] = pos1 @@ -1061,7 +1062,9 @@ worldedit.register_command("transpose", { local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if axis1 == "?" then axis1 = worldedit.player_axis(name) end if axis2 == "?" then axis2 = worldedit.player_axis(name) end - local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2) + + local count = worldedit.transpose(pos1, pos2, axis1, axis2) + pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2) --reset markers to transposed positions worldedit.pos1[name] = pos1 @@ -1112,7 +1115,9 @@ worldedit.register_command("rotate", { func = function(name, axis, angle) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if axis == "?" then axis = worldedit.player_axis(name) end - local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle) + + local count = worldedit.rotate(pos1, pos2, axis, angle) + pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle) --reset markers to rotated positions worldedit.pos1[name] = pos1 @@ -1248,7 +1253,7 @@ worldedit.register_command("restore", { }) local function detect_misaligned_schematic(name, pos1, pos2) - pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1 = worldedit.sort_pos(pos1, pos2) -- Check that allocate/save can position the schematic correctly -- The expected behaviour is that the (0,0,0) corner of the schematic stays -- sat pos1, this only works when the minimum position is actually present diff --git a/worldedit_commands/mark.lua b/worldedit_commands/mark.lua index 9f7b020..7bfe661 100644 --- a/worldedit_commands/mark.lua +++ b/worldedit_commands/mark.lua @@ -4,7 +4,7 @@ worldedit.marker_region = {} --marks worldedit region position 1 worldedit.mark_pos1 = function(name) - local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] + local pos1 = worldedit.pos1[name] if pos1 ~= nil then --make area stay loaded @@ -27,7 +27,7 @@ end --marks worldedit region position 2 worldedit.mark_pos2 = function(name) - local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] + local pos2 = worldedit.pos2[name] if pos2 ~= nil then --make area stay loaded @@ -60,7 +60,7 @@ worldedit.mark_region = function(name) end if pos1 ~= nil and pos2 ~= nil then - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) local vec = vector.subtract(pos2, pos1) local maxside = math.max(vec.x, math.max(vec.y, vec.z))