VE Lua Documentation

Press F to search!

createGlobalSnapshot

Definition


-- @/lua/common/devUtils.lua:145

function createGlobalSnapshot(filename)
  -- general fixes
  if type(gui) == 'table' and type(gui.reset) == 'function' then gui.reset() end -- removes any temporary gui caches

  -- do the snapshot
  local snapshot = { tables = {}, tablesTmp = {}, vars = {}, extensions = {} }
  for k, v in pairs(_G) do
    if (type(v) == 'table' and (rawget(v, '___type') or rawget(v, '___getters'))) or type(v) == 'function' or k == '_G' or k == 'extensions' or k == 'package' then goto continue end
    if type(v) == 'table' and k ~= 'math' and k ~= 'ffi' and k ~= 'jit' and k ~= 'mime' and k ~= 'socket' then
      if rawget(v, '__extensionName__') then goto continue end
      local locals = getModuleLocals(v)
      local used = false
      local t = {}
      if not tableIsEmpty(locals) then t.locals = locals ; used = true end
      if not tableIsEmpty(v) then t.module = v ; used = true end
      if used then
        t.key = k
        snapshot.tablesTmp[tostring(v)] = t
      end
    else
      snapshot.vars[k] = deepcopy(v)
    end
    ::continue::
  end
  snapshot = _cleanupCloneTbl(snapshot, {}, '/')
  -- now cleanup the tables
  for k, v in pairs(snapshot.tablesTmp) do
    if v.module and v.module.__extensionName__ then
      v.key = nil
      snapshot.extensions[v.module.__extensionName__] = v
    else
      if v.module and not tableIsEmpty(v.module) then
        snapshot.tables[v.key] = v
        v.key = nil
      end
    end
  end
  snapshot.tablesTmp = nil
  --_createGraphvizFile(filename..'.dot', snapshot)
  flattenTable(snapshot)
  jsonWriteFile(filename, snapshot, true)
end

Callers