欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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