lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Okay all you smarty pants (tee hee)! I need to be able to replace the
> value of a line item in said conf files. This was my terrible attempt
> some moons ago:

As Sean has already mentioned, instead of identifying and changing a
particular line in your conf file, it would be much easier to just save
your full configuration again - unless you care about white space and
comments in the conf file. If not, the following minimal code would
write your conf table back to such a "INI-like" conf file:

function saveConfToFile (confTable, confFile)
  local f = io.open(confFile, 'w')
  if f==nil then return false end
  for k,v in pairs(confTable) do
    f:write(k..'='..v..'\n')
  end
  f:close()
  return true
end

Disclaimer: untested email code

Valentin