[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to get file size?
- From: Michal Kottman <k0mpjut0r@...>
- Date: Tue, 19 Apr 2011 12:19:50 +0200
On Tue, 2011-04-19 at 12:07 +0200, Gilles Ganault wrote:
> On Tue, 19 Apr 2011 11:42:38 +0200, Jerome Vuarand
> <jerome.vuarand@gmail.com> wrote:
> >You have to check the return value from io.open. It may be nil, and
> >followed by an error message:
> >
> >libs_file,msg = io.open("librt.so.0","r")
> >if not libs_file then
> > error(msg)
> >end
>
> Thanks for the tip. I tried both the above and assert() and found that
> they provide the same amount of information on the error.
Well, quoting from the manual [1]:
assert(v [, message])
Issues an error when the value of its argument v is false (i.e., nil or
false); otherwise, returns all its arguments. message is an error
message; when absent, it defaults to "assertion failed!"
In your case, io.open() returns either the file (which assert passes
untouched), or it returns nil, err, in which case assert() calls
error(err).
[1] http://www.lua.org/manual/5.1/manual.html#pdf-assert