我正在尝试为addon / weakaura排序表,但我不知道该怎么做(按attribut值排序)。
示例:
player = {
value = 34
class = Warrior,
id = 1
},
{
value = 1,
class = mage,
id = 2
},
{
value = 3443,
class = Paladin,,
class = 3
}
我想:
player = {
value = 1,
class = mage,
id = 2
},
{
value = 34
class = Warrior,
id = 1
},
{
value = 3443,
class = Paladin,
class = 3
}
有人知道如何做到这一点?
答案 0 :(得分:2)
假设您修复了表声明,可以使用自定义函数对表进行排序:
local player = {
{ value = 34, class = "Warrior", id = 1 },
{ value = 1, class = "mage", id = 2 },
{ value = 3443, class = "Paladin", id = 3 },
}
table.sort(player, function(a,b) return a.value < b.value end)
这将按player
字段的值对value
表的元素进行排序。如果需要,您可以提出更精细的分类条件。
有关table.sort
的更多信息,请参阅http://www.lua.org/manual/5.3/manual.html#pdf-table.sort