官方手册里早已经给了答案,那就是靠lua内置的next函数

即如此用:

a = {}

if next(a) == nil then

next其实就是pairs遍历table时用来取下一个内容的函数.

但是如果 a= nil 就会报错,所以还要先判断一下 a是否为nil。

 

于是封装后判断的lua table是否为空的函数如下:

function tableIsEmpty(t)
  if t == nil then return true end
  return _G.next(t) == nil
end

 

相关文章:

  • 2021-11-28
  • 2021-11-28
  • 2021-07-04
  • 2021-06-11
  • 2021-09-23
  • 2021-06-08
  • 2021-08-08
猜你喜欢
  • 2021-07-08
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-11-27
相关资源
相似解决方案