GE Lua Documentation

Press F to search!

tableDepth

Definition


-- @/lua/common/utils.lua:792

-- counts the depth of a table. Recursive, super slow
function tableDepth(tbl, lookup)
  if type(tbl) ~= 'table' then return 0 end
  lookup = lookup or {}
  local depth = 1
  for k, v in pairs(tbl) do
    if type(k) == "table" then
      lookup[k] = lookup[k] or tableDepth(k, lookup)
      depth = max(depth, lookup[k] + 1)
    end
    if type(v) == "table" then
      lookup[v] = lookup[v] or tableDepth(v, lookup)
      depth = max(depth, lookup[v] + 1)
    end
  end
  return depth
end

Callers

@/lua/common/utils.lua
    if type(k) == "table" then
      lookup[k] = lookup[k] or tableDepth(k, lookup)
      depth = max(depth, lookup[k] + 1)
    if type(v) == "table" then
      lookup[v] = lookup[v] or tableDepth(v, lookup)
      depth = max(depth, lookup[v] + 1)