Merge pull request #650 from kotisoff/main

Minor lua code refactor + typo fix
This commit is contained in:
MihailRis 2025-10-14 22:36:19 +03:00 committed by GitHub
commit 11403084e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 34 additions and 27 deletions

View File

@ -101,7 +101,7 @@ block.set_rotation(x: int, y: int, z: int, rotation: int)
## Extended blocks ## Extended blocks
Extended blocks are blocks with size greather than 1x1x1 Extended blocks are blocks with size greater than 1x1x1
```lua ```lua
-- Checks whether the block is extended. -- Checks whether the block is extended.

View File

@ -194,42 +194,49 @@ function Version.__equal(ver1, ver2)
return ver1[1] == ver2[1] and ver1[2] == ver2[2] and ver1[3] == ver2[3]; return ver1[1] == ver2[1] and ver1[2] == ver2[2] and ver1[3] == ver2[3];
end end
function Version.__more(ver1, ver2) function Version.__greater(ver1, ver2)
if ver1[1] ~= ver2[1] then return ver1[1] > ver2[1] end; if ver1[1] ~= ver2[1] then return ver1[1] > ver2[1] end;
if ver1[2] ~= ver2[2] then return ver1[2] > ver2[2] end; if ver1[2] ~= ver2[2] then return ver1[2] > ver2[2] end;
return ver1[3] > ver2[3]; return ver1[3] > ver2[3];
end end
function Version.__less(ver1, ver2) function Version.__less(ver1, ver2)
return Version.__more(ver2, ver1); return Version.__greater(ver2, ver1);
end end
function Version.__more_or_equal(ver1, ver2) function Version.__greater_or_equal(ver1, ver2)
return not Version.__less(ver1, ver2); return not Version.__less(ver1, ver2);
end end
function Version.__less_or_equal(ver1, ver2) function Version.__less_or_equal(ver1, ver2)
return not Version.__more(ver1, ver2); return not Version.__greater(ver1, ver2);
end end
Version.operators = {
["="] = Version.__equal,
[">"] = Version.__greater,
["<"] = Version.__less,
[">="] = Version.__greater_or_equal,
["<="] = Version.__less_or_equal
}
function Version.compare(op, ver1, ver2) function Version.compare(op, ver1, ver2)
ver1 = string.split(ver1, "."); ver1 = string.split(ver1, ".");
ver2 = string.split(ver2, "."); ver2 = string.split(ver2, ".");
if op == "=" then return Version.__equal(ver1, ver2); local comparison_func = Version.operators[op];
elseif op == ">" then return Version.__more(ver1, ver2);
elseif op == "<" then return Version.__less(ver1, ver2); if comparison_func then
elseif op == ">=" then return Version.__more_or_equal(ver1, ver2); return comparison_func(ver1, ver2);
elseif op == "<=" then return Version.__less_or_equal(ver1, ver2); else
else return false; end return false;
end
end end
function Version.parse(version) function Version.parse(version)
local op = string.sub(version, 1, 2); local op = string.sub(version, 1, 2);
if op == ">=" or op == "=>" then if op == ">=" or op == "<=" then
return ">=", string.sub(version, #op + 1); return op, string.sub(version, #op + 1);
elseif op == "<=" or op == "=<" then
return "<=", string.sub(version, #op + 1);
end end
op = string.sub(version, 1, 1); op = string.sub(version, 1, 1);

View File

@ -27,15 +27,15 @@ public:
}; };
enum class VersionOperator { enum class VersionOperator {
EQUAL, GREATHER, LESS, EQUAL, GREATER, LESS,
GREATHER_OR_EQUAL, LESS_OR_EQUAL GREATER_OR_EQUAL, LESS_OR_EQUAL
}; };
VC_ENUM_METADATA(VersionOperator) VC_ENUM_METADATA(VersionOperator)
{"=", VersionOperator::EQUAL}, {"=", VersionOperator::EQUAL},
{">", VersionOperator::GREATHER}, {">", VersionOperator::GREATER},
{"<", VersionOperator::LESS}, {"<", VersionOperator::LESS},
{">=", VersionOperator::GREATHER_OR_EQUAL}, {">=", VersionOperator::GREATER_OR_EQUAL},
{"<=", VersionOperator::LESS_OR_EQUAL}, {"<=", VersionOperator::LESS_OR_EQUAL},
VC_ENUM_END VC_ENUM_END

View File

@ -37,13 +37,13 @@ public:
switch (op) { switch (op) {
case VersionOperator::EQUAL: case VersionOperator::EQUAL:
return *this == other; return *this == other;
case VersionOperator::GREATHER: case VersionOperator::GREATER:
return *this > other; return *this > other;
case VersionOperator::LESS: case VersionOperator::LESS:
return *this < other; return *this < other;
case VersionOperator::LESS_OR_EQUAL: case VersionOperator::LESS_OR_EQUAL:
return *this <= other; return *this <= other;
case VersionOperator::GREATHER_OR_EQUAL: case VersionOperator::GREATER_OR_EQUAL:
return *this >= other; return *this >= other;
default: default:
return false; return false;

View File

@ -54,7 +54,7 @@ public:
/// @brief Build atlas from all added images /// @brief Build atlas from all added images
/// @param extrusion textures extrusion pixels /// @param extrusion textures extrusion pixels
/// (greather is less mip-mapping artifacts) /// (greater is less mip-mapping artifacts)
/// @param prepare generate atlas texture (calls .prepare()) /// @param prepare generate atlas texture (calls .prepare())
/// @param maxResolution max atlas resolution /// @param maxResolution max atlas resolution
std::unique_ptr<Atlas> build(uint extrusion, bool prepare=true, uint maxResolution=0); std::unique_ptr<Atlas> build(uint extrusion, bool prepare=true, uint maxResolution=0);

View File

@ -25,7 +25,7 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
/// @brief Not greather than 64 for this BIG_PRIME value /// @brief Not greater than 64 for this BIG_PRIME value
inline constexpr int UPDATE_AREA_DIAMETER = 32; inline constexpr int UPDATE_AREA_DIAMETER = 32;
/// @brief Number of blocks in the volume /// @brief Number of blocks in the volume
inline constexpr int UPDATE_BLOCKS = inline constexpr int UPDATE_BLOCKS =

View File

@ -44,7 +44,7 @@ namespace gui {
runnable onDownPressed; runnable onDownPressed;
/// @brief Is current input valid /// @brief Is current input valid
bool valid = true; bool valid = true;
/// @brief Text input pointer, value may be greather than text length /// @brief Text input pointer, value may be greater than text length
size_t caret = 0; size_t caret = 0;
/// @brief Actual local (line) position of the caret on vertical move /// @brief Actual local (line) position of the caret on vertical move
size_t maxLocalCaret = 0; size_t maxLocalCaret = 0;

View File

@ -272,7 +272,7 @@ static int l_meta_meta_call(lua::State* L) {
auto width = tointeger(L, 2); auto width = tointeger(L, 2);
auto height = tointeger(L, 3); auto height = tointeger(L, 3);
if (width <= 0 || height <= 0) { if (width <= 0 || height <= 0) {
throw std::runtime_error("width and height must be greather than 0"); throw std::runtime_error("width and height must be greater than 0");
} }
return newuserdata<LuaHeightmap>( return newuserdata<LuaHeightmap>(
L, static_cast<uint>(width), static_cast<uint>(height) L, static_cast<uint>(width), static_cast<uint>(height)

View File

@ -276,7 +276,7 @@ public:
/// @brief does the block emit any lights /// @brief does the block emit any lights
bool emissive = false; bool emissive = false;
// @brief block size is greather than 1x1x1 // @brief block size is greater than 1x1x1
bool extended = false; bool extended = false;
/// @brief set of hitboxes sets with all coord-systems precalculated /// @brief set of hitboxes sets with all coord-systems precalculated