lujian101 / LuaTableOptimizer

simple readonly lua table optimizer
283 stars 85 forks source link

序列化列表的时候,这个排序有问题 #6

Closed zsmhunter closed 4 years ago

zsmhunter commented 4 years ago

image 如果key值同时有number跟string的话,sort就会有问题

lujian101 commented 4 years ago

thank you.

please try:

table.sort(
        sortedK,
    function( l, r )
        local lt = type( l )
        local rt = type( r )
        if lt ~= rt then
            return lt < rt
        else
            return l < r
        end
    end
)
zsmhunter commented 4 years ago

个人不建议这么sort。这样lua的排序会出现乱序问题,会报错的,我现在的做法是判断到有类型不同,直接换了个sortfunction image