[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua source as config file
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 8 Feb 2007 09:14:02 -0200
> 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
But I mean something with load (untested):
function loadconfig(file)
local state=0
local f = assert(io.open( file ))
load(function()
if state==0 then
state=1
return "return {"
elseif state==1 then
local s=f:read()
if s==nil then state=2 s=}" end
return s
else
return nil
end
end)
end
--lhf