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( "@", ... )
end

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

print( "hello" )

> @       hello

io.write( "hello" )

>@hello

etc...

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

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/