Hidden Features

lua-users home

The Lua C API and standard libraries may contain some undocumented, unsupported, and/or experimental features. They are likely unsupported for a good reason, and may disappear or change at any time--use them at your own risk.

Closing a standard file

As of 5.1.3, it is not permitted to close a standard file (e.g. stdin, stdout, and stderr) due to a bug this can cause[1][5]:

> assert(io.stdout:close())
stdin:1: cannot close standard file

Here's a hack around that, which should be used with caution:

local f = assert(io.open '/dev/null') -- or possibly NUL on Windows
debug.setfenv(io.stdout, debug.getfenv(f))
assert(io.stdout:close()) -- ok

Old items

See also

RecentChanges · preferences
edit · history
Last edited September 27, 2014 12:46 am GMT (diff)