From d74427e0174fb8e4999f15c5fbaa32f7b7d41d31 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 2 Oct 2024 01:17:41 +0100 Subject: [PATCH] Fix some luacheck errors the others are because rotate.lua isn't finished Unfortunately I don't have the time to fix it now, because it will require a lot of time --- .luacheckrc | 5 +++-- promise.lua | 2 +- worldeditadditions_commands/commands/set.lua | 2 +- worldeditadditions_core/utils/orientation.lua | 18 +++++++++--------- .../utils/parse/axes_rotation.lua | 2 +- .../utils/table/table_find.lua | 2 +- .../utils/table/table_tostring.lua | 4 ++-- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index fdc8c27..a7bd5d8 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -21,7 +21,7 @@ globals = { "worldedit", "worldeditadditions", "worldeditadditions_commands", - "worldeditadditions_core" + "worldeditadditions_core", } -- Read-only globals read_globals = { @@ -35,6 +35,7 @@ read_globals = { "dofile", "PerlinNoise", "Settings", - "VoxelArea" + "VoxelArea", + "pova" -- optional mod support } std = "max" diff --git a/promise.lua b/promise.lua index 3f1053e..8da0b79 100644 --- a/promise.lua +++ b/promise.lua @@ -145,7 +145,7 @@ end -- TEST example code, TODO test this -function test() +local function test() return Promise.new(function(resolve, reject) -- TODO do something asyncy here print("DEBUG running test function") diff --git a/worldeditadditions_commands/commands/set.lua b/worldeditadditions_commands/commands/set.lua index 1d5580f..5279ef6 100644 --- a/worldeditadditions_commands/commands/set.lua +++ b/worldeditadditions_commands/commands/set.lua @@ -22,7 +22,7 @@ core.register_command("set+", { local parts = core.split_shell(params_text) local mode = "param" - local value = nil + local value -- defaults to nil local possible_modes = { "param", "p", "param2", "p2", "light", "l" } diff --git a/worldeditadditions_core/utils/orientation.lua b/worldeditadditions_core/utils/orientation.lua index 18cf72c..675c4a5 100644 --- a/worldeditadditions_core/utils/orientation.lua +++ b/worldeditadditions_core/utils/orientation.lua @@ -17,7 +17,7 @@ local wallmounted_cycles = { } -- We have standardised on radians for other rotation operations, so it wouldn't make sense for the API-facing functions in this file to use a number of times or degrees, as this would be inconsistent -function convert_normalise_rad(rad) +local function convert_normalise_rad(rad) local deg = math.deg(rad) local times = worldeditadditions_core.round(deg / 90) return math.floor(times) -- ensure it's an integer and not e.g. a float 1.0 @@ -35,16 +35,16 @@ end -- @param axis string The name of the axis to rotate around. Valid values: `x`, `y`, `z` -- @param amount The number of radians to rotate around the given `axis`. Only right angles are supported (i.e. 90° increments). Any value that isn't a 90° increment will be **rounded**! -- @returns number A new param2 value that is rotated the given number of degrees around the given `axis` -function facedir(param2, axis, amount_rad) +local function facedir(param2, axis, amount_rad) local amount = convert_normalise_rad(amount_rad) print("DEBUG:core/orientation:facedir AMOUNT rad "..tostring(amount_rad).." norm "..tostring(amount)) - local facedir = param2 % 32 + local facedir_this = param2 % 32 for _, cycle in ipairs(facedir_cycles[axis]) do -- Find the current facedir -- Minetest adds table.indexof, but I refuse to use it because it returns -1 rather than nil for i, fd in ipairs(cycle) do - if fd == facedir then - return param2 - facedir + cycle[1 + (i - 1 + amount) % 4] -- If only Lua didn't use 1 indexing... + if fd == facedir_this then + return param2 - facedir_this + cycle[1 + (i - 1 + amount) % 4] -- If only Lua didn't use 1 indexing... end end end @@ -56,14 +56,14 @@ end -- @param axis string The name of the axis to rotate around. Valid values: `x`, `y`, `z` -- @param amount The number of radians to rotate around the given `axis`. Only right angles are supported (i.e. 90° increments). Any value that isn't a 90° increment will be **rounded**! -- @returns number A new param2 value that is rotated the given number of degrees around the given `axis` -function wallmounted(param2, axis, amount_rad) +local function wallmounted(param2, axis, amount_rad) local amount = convert_normalise_rad(amount_rad) print("DEBUG:core/orientation:wallmounted AMOUNT rad " .. tostring(amount_rad) .. " norm " .. tostring(amount)) - local wallmounted = param2 % 8 + local wallmounted_this = param2 % 8 for i, wm in ipairs(wallmounted_cycles[axis]) do - if wm == wallmounted then - return param2 - wallmounted + wallmounted_cycles[axis][1 + (i - 1 + amount) % 4] + if wm == wallmounted_this then + return param2 - wallmounted_this + wallmounted_cycles[axis][1 + (i - 1 + amount) % 4] end end return param2 diff --git a/worldeditadditions_core/utils/parse/axes_rotation.lua b/worldeditadditions_core/utils/parse/axes_rotation.lua index 3705837..ef4a69f 100644 --- a/worldeditadditions_core/utils/parse/axes_rotation.lua +++ b/worldeditadditions_core/utils/parse/axes_rotation.lua @@ -15,7 +15,7 @@ local function calc_rotation_text(rotation) end end -function rot_axis_left(axis) +local function rot_axis_left(axis) if axis.x == 1 or axis.x == -1 then axis.x, axis.z = 0, axis.x elseif axis.z == 1 or axis.z == -1 then diff --git a/worldeditadditions_core/utils/table/table_find.lua b/worldeditadditions_core/utils/table/table_find.lua index fc3b5b2..2b94ab3 100644 --- a/worldeditadditions_core/utils/table/table_find.lua +++ b/worldeditadditions_core/utils/table/table_find.lua @@ -12,7 +12,7 @@ -- 2. `i` (number): The index in the table that the value can be found at -- 3. `tbl` (table): The original table. -- @return any|nil The first element in the table that satisfies the predicate, or nil if no such element is found. -function find(tbl, func) +local function find(tbl, func) for i,value in ipairs(tbl) do if func(value, i, tbl) then return value diff --git a/worldeditadditions_core/utils/table/table_tostring.lua b/worldeditadditions_core/utils/table/table_tostring.lua index 8b9df3a..35b312f 100644 --- a/worldeditadditions_core/utils/table/table_tostring.lua +++ b/worldeditadditions_core/utils/table/table_tostring.lua @@ -3,7 +3,7 @@ --- Returns the key value pairs in a table as a single string -- @param tbl table input table --- @param sep string key value seperator +-- @param sep string key value separator -- @param new_line string key value pair delimiter -- @param max_depth number max recursion depth (optional) -- @return string concatenated table pairs @@ -17,7 +17,7 @@ local function tostring(tbl, sep, new_line, max_depth) for key,value in pairs(tbl) do if type(value) == "table" and max_depth.depth < max_depth.max then table.insert(ret,tostring(key) .. sep .. - "{" .. table_tostring(value,sep,new_line,{max_depth.depth+1,max_depth.max}) .. "}") + "{" .. tostring(value,sep,new_line,{max_depth.depth+1,max_depth.max}) .. "}") else table.insert(ret,tostring(key) .. sep .. tostring(value)) end