lua 对表做空判断

  • next 函数

首推使用next函数 对表做空判断。

使用方法:

function test()
    local tbl_hqyd = {}
    if not next(tbl_hqyd) then 
        return 
    end
end
  • 对表做遍历

这里是对表做遍历,返回表中数据的个数。

function get_table_real_count(t)
  local i = 0
  for k,v in pairs(t) do
    i = i + 1
  end
  return i
end

 

你可能感兴趣的:(lua)