Lua对字段进行排序

--对字段进行排序
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)