[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to get parameter names when in set_trace_func callback?

Stephen Kellett

12/11/2004 6:43:00 PM

Hi folks,

When my code is executing my trace_function set using set_trace_func how
do I get the parameter names of the function that is being traced? Say
for example I had a function

def myFunc(firstName, secondName, age)
do whatever 1
do whatever 2
do whatever 3
end

and my trace function has been called for a line execution event for "do
whatever 2". I can get the filename and line number from the binding.
How do I get the parameter names?

I've spent all this afternoon trying to do this, examining the Ruby
source, but can't work it out. Hope someone can help me, or tell me it
can't be done :-(

Stephen
--
Stephen Kellett
Object Media Limited http://www.objmedia.d...
RSI Information: http://www.objmedia.d.../rsi.html
3 Answers

Kent Sibilev

12/12/2004 5:43:00 AM

0

AFAIK, There is no official way to get names of method parameters. But
you can try this:

def m(a,b)
end

tracer = lambda do |*args|
p eval("local_variables", args[4]) if args[0] == 'call'
end

set_trace_func tracer
m(1, 2)

Cheers,
Kent.

On Dec 11, 2004, at 1:47 PM, Stephen Kellett wrote:

> Hi folks,
>
> When my code is executing my trace_function set using set_trace_func
> how
> do I get the parameter names of the function that is being traced? Say
> for example I had a function
>
> def myFunc(firstName, secondName, age)
> do whatever 1
> do whatever 2
> do whatever 3
> end
>
> and my trace function has been called for a line execution event for
> "do
> whatever 2". I can get the filename and line number from the binding.
> How do I get the parameter names?
>
> I've spent all this afternoon trying to do this, examining the Ruby
> source, but can't work it out. Hope someone can help me, or tell me it
> can't be done :-(
>
> Stephen
> --
> Stephen Kellett
> Object Media Limited http://www.objmedia.d...
> RSI Information: http://www.objmedia.d.../rsi.html
>



Stephen Kellett

12/12/2004 9:15:00 AM

0

In message <AA21DE54-4C00-11D9-B79B-000A95C700E8@bellsouth.net>, Kent
Sibilev <ksibilev@bellsouth.net> writes
>AFAIK, There is no official way to get names of method parameters. But
>you can try this:
>
>def m(a,b)
>end
>
>tracer = lambda do |*args|
> p eval("local_variables", args[4]) if args[0] == 'call'
>end
>
>set_trace_func tracer
>m(1, 2)

I think what you are saying is that when it is "call", local variables
actually has a copy of the parameters, even though at a subsequent
"line" - say the next statement executed - the local variables may hold
more data items. Hadn't thought about it that way.

Thanks

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

Robert Klemme

12/13/2004 9:33:00 AM

0


"Stephen Kellett" <snail@objmedia.demon.co.uk> schrieb im Newsbeitrag
news:VrZ6HmAe+zuBFw+o@objmedia.demon.co.uk...
> Hi folks,
>
> When my code is executing my trace_function set using set_trace_func how
> do I get the parameter names of the function that is being traced? Say
> for example I had a function
>
> def myFunc(firstName, secondName, age)
> do whatever 1
> do whatever 2
> do whatever 3
> end
>
> and my trace function has been called for a line execution event for "do
> whatever 2". I can get the filename and line number from the binding.
> How do I get the parameter names?
>
> I've spent all this afternoon trying to do this, examining the Ruby
> source, but can't work it out. Hope someone can help me, or tell me it
> can't be done :-(

I believe you can't other than patching the Ruby interpreter to add an
argument to the block invoked for tracing.

Kind regards

robert