[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How does one redefine io.stderr:write() function?
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sat, 20 Jun 2020 12:02:22 -0300
> 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.