[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: who called me?
From: |
John W. Eaton |
Subject: |
Re: who called me? |
Date: |
Wed, 22 Oct 2008 14:12:07 -0400 |
On 22-Oct-2008, Ben Abbott wrote:
|
| On Wednesday, October 22, 2008, at 11:44AM, "Søren Hauberg" <address@hidden>
wrote:
| >ons, 22 10 2008 kl. 11:30 -0400, skrev John W. Eaton:
| >> On 22-Oct-2008, Søren Hauberg wrote:
| >>
| >> | Assuming I have a function 'f1', how can I get the name of whatever
| >> | function called 'f1'?
| >> | I've tried to do this with a combination of 'evalin' and 'mfilename':
| >> |
| >> | function f1 ()
| >> | who_called_me = evalin ('caller', 'mfilename ()')
| >> | end
| >> |
| >> | but that just gives me the name of 'f1'.
| >>
| >> With the current development sources, you can use
| >>
| >> function f1 ()
| >> x = dbstack ();
| >> if (numel (x) > 1)
| >> caller = x(2).name
| >> else
| >> caller = "base"
| >> endif
| >> endfunction
| >
| >Thanks! Works like a charm.
| >
| >Søren
|
| I've often wanted to check on who called a particular function.
|
| Might it be possible to look one more caller back and write a general
function like
|
| call = whocalledme ();
Yes, you could write
function retval = who_called_me ()
x = dbstack ();
if (numel (x) > 2)
retval = x(3).name;
else
retval = "base";
endif
endfunction
jwe