VE Lua Documentation

Press F to search!

getSerializationData

Definition


-- @/lua/common/extensions.lua:944

local function getSerializationData(reason)
  if reason == nil then reason = 'reload' end
  local tmp = {}
  tmp['extensions'] = {}

  -- filter out virtual extensions
  local loadedModules = {}
  for k, m in pairs(luaMods) do
    local ignoreExtension = tableContains(doNotSerializeModules, m.__extensionName__)
    if not ignoreExtension then
      if not m.__virtual__ then
        loadedModules[k] = m.__extensionPath__
      end
    end
  end
  tmp['extensions'].loadedModules = loadedModules

  -- We need to make a copy of the resolvedModules table as modules calls extensions.unloadExcept will alter it as part of the execution flow.
  -- This fixes the bug where some modules do not get onDeserialize called because they have been dropped from these tables
  local tempResolvedModules = shallowcopy(resolvedModules)

  for _, v in ipairs(tempResolvedModules) do
    local ignoreExtension = tableContains(doNotSerializeModules, v.__extensionName__)
    if ignoreExtension then
      goto continue
    end
    local k = v.__extensionName__
    if type(v) == 'table' and v.__virtual__ ~= true and (v['onDeserialized'] ~= nil or v['onDeserialize'] ~= nil or v['onSerialize'] ~= nil) then
      if type(v['onSerialize']) == 'function' then
        -- if serialization function is existing, use that
        tmp[k] = v['onSerialize'](reason)
      elseif v['state']  then
        -- if M.state is existing, use only that
        tmp[k] = v.state
      else
        -- fallback: whole M
        tmp[k] = v
      end
    end
    ::continue::
  end

  -- unload all extension modules
  unloadExcept()

  return tmp
end

Callers

@/lua/common/utils.lua

  tableMergeExceptFunc(tmp, extensions.getSerializationData(reason))
  return tmp