lua-users home
lua-l archive

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

On Dec 02, 2005, at 00:03, Jens Alfke wrote:

What I want to do is redirect Lua output to my own function, so that calls to print(), io.write(), io.output():write(), etc. all call my function so it can collect the output and do something with it.

Not sure if this really what you want, but you can always redefine any functions:

local _print = print
local _write = io.write

function print( ... )
        _print( "@", ... )

function io.write( ... )
        _write( "@", ... )

print( "hello" )

> @       hello

io.write( "hello" )



Packages (e.g. io) are tables. The global environment (_G) is a table. You can redefine any table entry if you are so inclined :)


PA, Onnay Equitursay