From b637e0acc32faeeda669e135c546999c4a8e0c17 Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Sat, 30 Sep 2023 16:46:03 +0200 Subject: Sort keys by callback function --- tests/modules/table/test.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/modules/table/test.lua') diff --git a/tests/modules/table/test.lua b/tests/modules/table/test.lua index 007782cf4..297832575 100644 --- a/tests/modules/table/test.lua +++ b/tests/modules/table/test.lua @@ -29,3 +29,18 @@ function test_unwrap(t) local a = table.wrap_lock({1}) t:are_equal(table.unwrap(a), a) end + +function test_orderkeys(t) + -- sort by modulo 2 then from the smallest to largest + local f = function(a, b) + if a % 2 == 0 then + return true + elseif b % 2 == 0 then + return false + end + return a < b + end + + t:are_equal(table.orderkeys({[2] = 2, [1] = 1, [4] = 4, [3] = 3}, f), {2, 4, 1, 3}) + t:are_equal(table.orderkeys({[1] = 1, [2] = 2, [3] = 3, [4] = 4}), {1, 2 , 3, 4}) +end -- cgit v1.3.1 From dbfde8ed4da11fd0221a88bfa267e9cf05457345 Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:16:31 +0200 Subject: Remove unnecessary underscore --- tests/modules/table/test.lua | 4 ++-- xmake/core/project/target.lua | 2 +- xmake/plugins/project/cmake/cmakelists.lua | 6 +++--- xmake/plugins/project/ninja/build_ninja.lua | 2 +- xmake/plugins/project/vstudio/impl/vs201x.lua | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/modules/table/test.lua') diff --git a/tests/modules/table/test.lua b/tests/modules/table/test.lua index 297832575..2b586e7a4 100644 --- a/tests/modules/table/test.lua +++ b/tests/modules/table/test.lua @@ -33,9 +33,9 @@ end function test_orderkeys(t) -- sort by modulo 2 then from the smallest to largest local f = function(a, b) - if a % 2 == 0 then + if a % 2 == 0 and b % 2 ~= 0 then return true - elseif b % 2 == 0 then + elseif b % 2 == 0 and a % 2 ~= 0 then return false end return a < b diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index e8da135af..4f611368b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1862,7 +1862,7 @@ function _instance:sourcekinds() local sourcekinds = self._SOURCEKINDS if not sourcekinds then sourcekinds = {} - local sourcebatches, _ = self:sourcebatches() + local sourcebatches = self:sourcebatches() for _, sourcebatch in table.orderpairs(sourcebatches) do local sourcekind = sourcebatch.sourcekind if sourcekind then diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index e0b12ae1a..8a7eabb78 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -381,7 +381,7 @@ end function _add_target_sources(cmakelists, target, outputdir) local has_cuda = false cmakelists:print("target_sources(%s PRIVATE", target:name()) - local sourcebatches, _ = target:sourcebatches() + local sourcebatches = target:sourcebatches() for _, sourcebatch in table.orderpairs(sourcebatches) do if _sourcebatch_is_built(sourcebatch) then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do @@ -613,7 +613,7 @@ function _add_target_compile_options(cmakelists, target, outputdir) end -- add cflags/cxxflags for the specific source files - local sourcebatches, _ = target:sourcebatches() + local sourcebatches = target:sourcebatches() for _, sourcebatch in table.orderpairs(sourcebatches) do if _sourcebatch_is_built(sourcebatch) then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do @@ -837,7 +837,7 @@ function _add_target_link_libraries(cmakelists, target, outputdir) -- add other object files, maybe from custom rules local objectfiles_set = hashset.new() - local sourcebatches, _ = target:sourcebatches() + local sourcebatches = target:sourcebatches() for _, sourcebatch in table.orderpairs(sourcebatches) do if _sourcebatch_is_built(sourcebatch) then for _, objectfile in ipairs(sourcebatch.objectfiles) do diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua index 8e5677e45..2e55faf05 100644 --- a/xmake/plugins/project/ninja/build_ninja.lua +++ b/xmake/plugins/project/ninja/build_ninja.lua @@ -366,7 +366,7 @@ function _add_build_for_target(ninjafile, target, outputdir) ninjafile:print("") -- build target objects - local sourcebatches, _ = target:sourcebatches() + local sourcebatches = target:sourcebatches() for _, sourcebatch in table.orderpairs(sourcebatches) do if _sourcebatch_is_built(sourcebatch) then _add_build_for_objects(ninjafile, target, sourcebatch, outputdir) diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 699b5df47..1735c68a4 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -213,7 +213,7 @@ function _make_custom_commands(target, vcxprojdir) local commands = {} _make_custom_commands_for_target(commands, target, vcxprojdir, "before") _make_custom_commands_for_target(commands, target, vcxprojdir) - local sourcebatches, _ = target:sourcebatches() + local sourcebatches = target:sourcebatches() for _, sourcebatch in table.orderpairs(sourcebatches) do local rulename = sourcebatch.rulename local sourcekind = sourcebatch.sourcekind @@ -282,7 +282,7 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) local firstcompflags = nil targetinfo.compflags = {} targetinfo.compargvs = {} - local sourcebatches, _ = target:sourcebatches() + local sourcebatches = target:sourcebatches() for _, sourcebatch in table.orderpairs(sourcebatches) do local sourcekind = sourcebatch.sourcekind local rulename = sourcebatch.rulename -- cgit v1.3.1