lua-users home
lua-l archive

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


Assuming that you are using Lua 5.3, take a look at https://www.lua.org/manual/5.3/manual.html#6.8 (I/O Functions):

...
io.close ([file])
Equivalent to file:close(). Without a file, closes the default output file.
...

This, together with the knowledge that "table:function(args)" syntax is syntatic sugar for "table.function(table, args)" explains the behaviour you are experiencing. Been there as well.

Cheers,

Diogo


2017-02-02 13:08 GMT-02:00 Viacheslav Usov <via.usov@gmail.com>:
If f is variable holding the IO library's file object, then, to close the file, one needs to say f:close().

Note the reference manual documents only this use, with the colon syntax.

One, however, could also write f.close(). It is a pretty simple error to make, as I just learned from a colleague. What is the effect of that?

The reference manual does not say.

Looking at the implementation, what seems to happen is that the standard output handle gets closed instead! I'd say this is a bug.

I think f.close() should result in an error just like it does with f.read() and the other file functions.

Cheers,
V.