0%

问题背景

  • 排序出现报错
  • 排序顺序不正确的现象

报错

1
invalid order function for sorting

出现了一次报错,但是在测试过程中没有复现,之后项目中出现了相同报错导致场景打不开。

顺序不正确

例子(功能:对一系列名称进行排序):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- 输入:a1, a2, a3, b1, b2, b3, chusheng, a5, a10, a4, b7, b8, marker15, marker16, marker17, marker18, marker19
local function compfunc(s1, s2)
-- s1,s2分为数字段和非数字段,依次进行对比,比如b1和b2,先比较b和b,再比较1和2
for i = 1, math.min(#s1tokens, #s2tokens) do
if s1tokens[1] ~= s1tokens[2] then
return -- 返回比较结果
end
end
return #s1tokens <= #s2tokens
end

table.sort(names, compfunc)
-- 期待的结果:a1, a2, a3, a4, a5, a10, b1, b2, b3, b7, b8, chusheng, marker15, marker16, marker17, marker18, marker19
-- 实际的结果:a1, a2, a3, a4, a5, a10, b1, b2, b8, b3, b7, chusheng, marker15, marker16, marker17, marker18, marker19
阅读全文 »

Hexo

一种静态博客框架

常用命令

1
2
3
4
5
6
hexo new <title>

# hexo generate
hexo s # hexo server

hexo deploy

分类和标签

1
2
3
4
5
6
7
categories:
- [Diary, PlayStation]
- [Diary, Games]
- [Life]
tags:
- PS3
- Games
阅读全文 »