invalid order function for sorting

来源:互联网 发布:shipyard 增加node 编辑:程序博客网 时间:2024/06/05 20:07
t = {
        {lv = 1 , score =2,id = 1 },
        {lv = 1 , score =2 ,id = 2},
        {lv = 1 , score =2 ,id = 3},
        {lv = 1 , score =2 ,id = 4}
    }
function compFunc(a, b)
    if a.score == b.score then
        if a.lv == b.lv then 
        return true -- return true cause "invalid order function for sorting" , must return false here
        else
        return a.lv > b.lv
        end
    else
        return a.score > b.score
    end
end


table.sort(t,compFunc)
阅读全文
0 0
原创粉丝点击