lua source as config file

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: lua source as config file

Petite Abeille

On Feb 08, 2007, at 23:46, Doug Rogers wrote:

PA wrote:
function config( aPath )
        local aChunck = setfenv( loadfile( aPath ), {} )
        return getfenv( aChunck, aChunck() )
end
Thoughts?

I like this. The only drawback is that in operational code you will have
to catch any errors raised by loadfile(). It also makes config()
unusable after such an error...

Hmmm... yes... very unfortunate... but as Roberto mentioned somewhere else in this thread... a well placed assert should prevent such a disaster:

function config( aPath )
        local aChunk = setfenv( assert( loadfile( aPath ) ), {} )

        return getfenv( aChunk, aChunk() )
end


12