Lua对字段进行排序
程序员文章站
2022-03-14 11:00:49
...
--对字段进行排序
guild = {}
table.insert(guild, {name = "Cladhaire",class = "Rogue",level = 70,})
table.insert(guild, {name = "Sagart",class = "Priest",level = 70,})
table.insert(guild, {name = "Mallaithe",class = "Warlock",level = 40,})
--排序规则,对name按升序排序
function sortLevelNameAsc(a, b)
return a.name <b.name
end
table.sort(guild, sortLevelNameAsc)
for idx, value in ipairs(guild) do print(idx, value.name) end
上一篇: 各类排序总结
下一篇: Lua的闭包详解(转)