coding

Just So So ...

首页 关于

table.sort报错:invalid order function for sorting

  • 作者: aaron
  • 时间: 20210330
  • 分类: lua

使用table.sort时,碰到一个错误:invalid order function for sorting
原因是table.sort的比较函数返回的类型不是boolean

正确使用table.sort的方法:

-- 按数字大小降序排序
local t = { 1, 10, 8, 7}
table.sort(t, function (a, b)
    return a - b > 0
end)

-- 按数字大小升序排序
table.sort(t, function (a, b)
    return a - b < 0
end)

标签: lua

  • 上一篇: git提取指定分支指定文件或文件夹
  • 下一篇: Lua执行系统命令方法os.execute和io.popen

最新文章

  • Query Rewrite Plugin 安装与使用
  • 在openEuler-22.03-LTS上执行opengauss5.0.1的脚本gs_preinstall陷入死循环问题
  • oracle 11g 通过unlock打补丁PSU
  • Lua执行系统命令方法os.execute和io.popen
  • table.sort报错:invalid order function for sorting
  • git提取指定分支指定文件或文件夹
  • git删除分支
  • MySQL查询占用内存、CPU较高的SQL
  • MySQL 8.0 配置MGR事务一致性担保
  • oracle 19c克隆

分类

  • 默认分类
  • git
  • mysql
  • linux
  • lua
  • c
  • oracle
  • perl

归档

  • January 2025
  • April 2021
  • March 2021
  • October 2020
  • July 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • June 2018

其它

  • 文章 RSS
© 2025 coding. 由 Typecho 强力驱动. 粤ICP备17069618号