lua-users home
lua-l archive

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


On Wed, Sep 01, 2004 at 11:14:44AM -0300, Luiz Henrique de Figueiredo wrote:
> The only ANSI C way to do this is to open it:
> 
> 	function exists(n)
> 		local f=io.open(n)
> 		io.close(f)
> 		return f==nil
> 	end
> 
> > I've tried testing for for a valid return from io.open(), but if the file doesn't exist, Lua throws up a default error, never mind trying to run my own handling code...
> 
> It works for me:
> 
> % lua
> Lua 5.0  Copyright (C) 1994-2003 Tecgraf, PUC-Rio
> > print(io.open"/etc/passwd")
> file (0x80648b8)

$ lua -e 'print(io.open("/etc"))'
file (0x804f968)
$

Huh?

> > print(io.open"/etc/Passwd"); print"ok"
> nil     /etc/Passwd: No such file or directory  2
> ok
> --lhf