From 89eab3fb72597a1bef2d63e78fa4cf34810a549c Mon Sep 17 00:00:00 2001 From: Pablo Ariel Mayobre Date: Tue, 14 Feb 2023 18:14:08 -0300 Subject: [PATCH] List.sort Fixes #33 --- concord/list.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/concord/list.lua b/concord/list.lua index 1263a72..88dfc04 100644 --- a/concord/list.lua +++ b/concord/list.lua @@ -94,6 +94,20 @@ function List:indexOf(obj) return self[obj] end +--- Sorts the List in place, using the order function. +-- The order function is passed to table.sort internally so documentation on table.sort can be used as reference. +-- @param order Function that takes two Entities (a and b) and returns true if a should go before than b. +-- @treturn List self +function List:sort(order) + table.sort(self, order) + + for key, obj in ipairs(self) do + self[obj] = key + end + + return self +end + return setmetatable(List, { __call = function() return List.new()