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:

> 
> > Maybe something like this then ?
> 
> This code is slow because it concats the file line by line.
> See http://www.lua.org/pil/11.6.html
> 
> A better solution is to read it all at once:
> 
> function getconfig( file ) 
>   local f = assert(io.open( file ))
>   local ret = "return {" .. f:read"*a" .. "}"
>   f:close()
>   return ret
> end
> 

There is no way to parse the following format using your proposed func:

<file start>
option1 = "ok"
option2 = true
option3 = 34
<file end>

Watch that there are no commas and it really looks like a config file ;)
while what I suggest does this. It may take a little tweaking but it will get it.