lua-users home
lua-l archive

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



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