lua-users home
lua-l archive

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

On 6/13/07, RJP Computing <> wrote:
I am new to Lua so I apologize if this question is easy. I have a GUI
application that does not have a terminal and I wanted script writers to be
able to see there print() statements in the GUI. Now I am sure I could catch
the standard in and out, but that is a real pain. I was hoping I could
overwrite the print function in Lua to call my applications version of it
and then display it in my user interface. Can this be done?
Any function can be overwritten by reassigning its global... (you can
setup environment tables+metatables to prevent such overwriting.. but
thats another story.

Basically what you'd want to do is:
function print(...)
 local args = {...}
 for i = 1, select('#', ...) do

or more optimally
function print(...)
 local args = {...}
 for i = 1, select('#', ...) do if args[i] == nil then args[i] =
(somethingElse) end
 doSomeIO(table.concat(args, separator))

Hopefully that helps out
Thomas Harning Jr.