lua(2) table排序

player ={
   {name = "yangchun",id = "100000001"},
   {name = "dlnuchunge",id = "100000002"},
   {name = "nate",id = "100000003"},
}
function output(p)
   for k,v in pairs(p) do
      print(k,v.name)
   end
end

output(player)

table.sort(player,function(a,b) return(a.name < b.name) end)

output(player)

 

排序table.sort


注:发现lua是的读取顺序是从上往下。c#应该也是上往下,但是先读取了全局属性和方法。应该是这样把,呵呵,说错了大家纠正哈。

你可能感兴趣的:(lua(2) table排序)