lua-users home
lua-l archive

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


Luiz Henrique de Figueiredo <lhf <at> tecgraf.puc-rio.br> writes:

> 
> > but the return makes it look less like a config file.
> 
> Drop the return and the table constructor all together and use a custom
> dofile, one that adds "return {" at the beginning and "}" at the end.
> This will allow (and restrict) config files to be a series assignments.
> On the other hand, you'll need commas or semicolons after each assignments;
> semicolons seem better in this case.
> --lhf
> 
> 

Maybe something like this then ?

function getconfig( file ) 
  local f,e = io.open( file )
  if e then 
    return error( "No configuration! "..file.." not found!")
  end
  local ret = "return {"
  for line in f:lines() do
    ret = ret.."\r\n"..line..","
  end
  return ret.."\r\n}"
end