[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.1.3-rc4 now available
- From: David Manura <dm.lua@...>
- Date: Mon, 21 Jan 2008 18:36:14 +0000 (UTC)
Mike Pall writes:
> Ok, so stdin/stdout/stderr can no longer be closed from Lua [5.1.3] code.
It's possible with the debug library. Here's the hack I posted in
local f = assert(io.open '/dev/null') -- or possibly NUL on Windows
debug.setfenv(io.stdout, debug.getfenv(f)) -- make closable
assert(io.stdout:close()) -- succeeds
> E.g. stdin may have been closed from C code or may not be open to
> begin with (for daemon processes, though it's customary to
> freopen() to /dev/null to avoid these kind of problems).
In my case, I have a GUI application where stdin is not really open to begin
with. Here's the solution I used after applying 5.1.3:
lua_getfield(m_L, -1, "stdin");
FILE** f = (FILE**)lua_touserdata(m_L, -1);
*f = NULL;
Now, operations on io.stdin result in the error "attempt to use a closed file".