lua-users home
lua-l archive

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


>In 4.0, I'd write something like:
>
>if( not dofile( os.getenv("HOME") .. "/.ps2luarc" )) then
>    print( "no user config file - using defaults." );
>end
>
>what's the right way to do this in 5.0 -- i.e. dealing gracefully in 
>cases where the file does not exist?

There's a dofile in 5.0, but it emits and error when the file cannot be
found or when there are syntax errors. If that's not what you want, you'll
have to use loadfile:

 local f,e=loadfile(os.getenv("HOME") .. "/.ps2luarc")
 if f then f() else print( "no user config file - using defaults." ) end

If you want to trap execution errors in f, then use pcall.
--lhf