How can I get the return value from a Ruby function, but inside the set_trace_func callback?

Hi folks,

When my code is executing my trace_function set using set_trace_func how
do I get the return value for a ruby return event? Say for example I had
a function

        def myFunc(arg1, arg2)
                result = arg1 * arg2
        end

and my trace function has been called for the return event for the
myFunc() function. The function always returns the last data item
evaluated, which in this case is result. Can I determine this value from
inside the trace function? If I can how do I do so?

I've spent all this afternoon trying to do this (and the other problem
in my other question), examining the Ruby source, but can't work it out.
Hope someone can help me, or tell me it can't be done :frowning:

Stephen

···

--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk
RSI Information: http://www.objmedia.demon.co.uk/rsi.html

Stephen Kellett wrote:

Hi folks,

When my code is executing my trace_function set using set_trace_func how
do I get the return value for a ruby return event? Say for example I had
a function

        def myFunc(arg1, arg2)
                result = arg1 * arg2
        end

and my trace function has been called for the return event for the
myFunc() function. The function always returns the last data item
evaluated, which in this case is result. Can I determine this value from
inside the trace function? If I can how do I do so?

I've spent all this afternoon trying to do this (and the other problem
in my other question), examining the Ruby source, but can't work it out.
Hope someone can help me, or tell me it can't be done :frowning:

Stephen

Stephen,

This is a complete shot-in-the-dark from a noob but have you tried adding this as the last line of the function?

return result

I heard somewhere it negatively impacts performance to add an explicit return statement in functions. Maybe the cause of this performace hit will be the same thing that helps when tracing.

Good luck.

I have tried this. It didn't work - but even if it did, it defeats the purpose. I need it to work without modifying the Ruby program.

Thanks all the same.

Stephen

···

In message <yAHud.7556$nE7.614@newssvr17.news.prodigy.com>, J. D. <jd@nospam.com> writes

This is a complete shot-in-the-dark from a noob but have you tried adding this as the last line of the function?

--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk
RSI Information: http://www.objmedia.demon.co.uk/rsi.html

J. D. ha scritto:

This is a complete shot-in-the-dark from a noob but have you tried adding this as the last line of the function?

return result

I heard somewhere it negatively impacts performance to add an explicit return statement in functions. Maybe the cause of this performace hit will be the same thing that helps when tracing.

this was true, but it is'nt anymore, nobu "the patch bot" nokada proposed a patch and that was accepted:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/91270