[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Stdout
- From: "Nick Trout" <nick@...>
- Date: Mon, 29 Jan 2001 13:36:37 -0000
Of course! and the same with print:
function print(x) %print('redirected:'..x) end
Cheers,
Nick
>Can I redirect output (ie. output from write()) into a memory buffer/Lua
>function without altering the Lua source?
Yes, by redefining write itself. Something like this:
_OUTBUF=""
function write(...)
if arg[1]==_OUTPUT or tag(arg[1])~=tag(_OUTPUT) then
local i0
if arg[1]==_OUTPUT then i0=2 else i0=1 end
for i=i0,arg.n do
_OUTBUF=_OUTBUF..arg[i]
end
else
call(%write,arg)
end
end
--lhf