GE Lua Documentation

Press F to search!

saveIni

Definition


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

function saveIni(filename, d)
  local c = {}

  -- sort the keys
  local dkeys = {}
  for k in pairs(d) do table.insert(dkeys, k) end
  table.sort(dkeys)

  -- save a header
  table.insert(c, '# ' .. beamng_windowtitle .. '\r\n')
  table.insert(c, '# ' .. beamng_buildinfo .. '\r\n')
  table.insert(c, '# saved on ' .. formatTimeStringNow('{YYYY}/{MM}/{DD} {HH}:{mm}:{ss}') .. '\r\n')

  -- save the text
  for _, k in pairs(dkeys) do
    local v = d[k]
    table.insert(c, ("%s = %s\r\n"):format(tostring(k), tostring(v)))
  end

  -- create the file
  local f = io.open(filename, "w")
  if not f then return end
  f:write(tableconcat(c, ""))
  f:close()
end

Callers