file:close return value

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

file:close return value

Lorenzo Donati-3
Hi List!

I just realized that the manual doesn't say much about the return value
of file:close for handles created by regular io.open.

A not-so-in-depth scan of liolib.c code seems to confirm my initial
assumption that, more or less, it returns what the underlying C fclose
function returns.

The problem is that this is not documented, but probably it should,
since a fclose failure may mean that the write-buffered data could have
been lost or something like that.

I didn't check thoroughly, but the same could apply to file:close (which
I assume it relies on C's fflush).

IMHO the manual should mention at least briefly what those methods
return in general. What do you think?

Cheers!

Lorenzo

P.S.: Happy (late) New Year :-)

Reply | Threaded
Open this post in threaded view
|

Re: file:close return value

Roberto Ierusalimschy
> I just realized that the manual doesn't say much about the return
> value of file:close for handles created by regular io.open.
>
> [...]
>
> IMHO the manual should mention at least briefly what those methods
> return in general. What do you think?

The manual says this:

  Unless otherwise stated, all I/O functions return nil on failure (plus
  an error message as a second result and a system-dependent error code
  as a third result) and some value different from nil on success.

  (http://www.lua.org/manual/5.3/manual.html#6.8)

What else could it say?

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: file:close return value

Lorenzo Donati-3


On 05/01/2016 20:14, Roberto Ierusalimschy wrote:

>> I just realized that the manual doesn't say much about the return
>> value of file:close for handles created by regular io.open.
>>
>> [...]
>>
>> IMHO the manual should mention at least briefly what those methods
>> return in general. What do you think?
>
> The manual says this:
>
>    Unless otherwise stated, all I/O functions return nil on failure (plus
>    an error message as a second result and a system-dependent error code
>    as a third result) and some value different from nil on success.
>
>    (http://www.lua.org/manual/5.3/manual.html#6.8)
>
> What else could it say?
>
> -- Roberto
>
>

Ouch! That is embarrassing!  =(8-O

I completely overlooked it!
I was sure I read it before (multiple times!), but skimming the manual
over and over didn't help today (OMG!).
That's really selective blindness in action!

To my partial defense, I've been rereading the manual over and over for
the last two weeks, since I'm preparing some selected documentation for
an introductory one-week (10 hours) crash course on Lua for
high-achieving students of my school that I will teach beginning next week.

A note to myself: stop reading when your eyes start bleeding!

Sorry for the noise!

-- Lorenzo