VE Lua Documentation

Press F to search!

loadIni

Definition


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

--MARK: Ini
-- plain, no section, no nested INI support
function loadIni(filename)
  local d = {}
  local f = io.open(filename, "r")
  if not f then return nil end
  for line in f:lines() do
    if string.len(line) > 0 then
      local firstChar = string.sub(line, 1, 1)
      if firstChar ~= '#' and firstChar ~= ';' and firstChar ~= '/' then
        local key, value = line:match("^([^%s=]+)%s-=%s-(.+)$")
        if key and value then
          value = trim(value)
          if tonumber(value) then
            value = tonumber(value)
          elseif value == "true" then
            value = true
          elseif value == "false" then
            value = false
          end
          d[key] = value
        else
          log("E", "", "Unable to parse INI line: "..line)
        end
      end
    end
  end
  f:close()
  return d
end

Callers