[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: dofile() in 5.0 - no such file
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 15 Jan 2003 07:10:45 -0200
>In 4.0, I'd write something like:
>if( not dofile( os.getenv("HOME") .. "/.ps2luarc" )) then
> print( "no user config file - using defaults." );
>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.