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 (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.



2017-02-02 13:08 GMT-02:00 Viacheslav Usov <>:
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 and the other file functions.