lua-users home
lua-l archive

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


>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