lua-users home
lua-l archive

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


> I would like to make calls to io.stderr:write() be silent sometimes but I am unable to redefine that function temporarily.

The write function used in io.stderr:write() resides in a metatable.
Try this code:

-- Trying to make io.stderr:write() be silent
local my_write = getmetatable(io.stderr).write
getmetatable(io.stderr).write = nothing
io.stderr:write("hello world yet again!\n")
-- Trying to make io.stderr:write() to work again
getmetatable(io.stderr).write = my_write
io.stderr:write("hello world yet again and again!\n")

However, note that this affects *all* files: it will disable write for
all files. The code above is ok for disabling write while no other
writes happen.