How do you get the name of a procedure's immediate caller?

Is there a way from within a procedure to identify the calling procedure at runtime? That is, if p1 and p2 both call px, can px determine at runtime which procedure (p1 or p2) was the caller?

One way, of course, is to add an input argument to px (e.g., callername). then p1 would issue the call px("p1") and p2 would issue px("p2"). Within px, callername would hold either "p1" or "p2".

But is there a function callable from px that will return "p1" or "p2" depending on which one was the caller.

As you say, either include an argument or use a variable to identify the procedure called.

This is fully possible, I had a lot of unreleased extensions that featured this... This is done through keeping track of the procedure calls i.e. stack tracing using dynamically injected hooks... This is how the Itoo-X framework does runtime code manipulation to facilitate certain features...

See the last two links in the advanced section

@Kumaraswamy, thanks for replying to this post! ...

You know what I am going to ask next :slight_smile: "Is there one of these extensions which would function in the current AI2 environment? ...perhaps "stripped down" to include only the traceback function... or (if it is easier) the immediate caller only.

Since it is you ("Mr. Itoo"), I will tell you that I have numerous procedures that MUST be called from the background process in an itoo environment. So, as a safety/debug technique, I am placing a call at the top of each one to procedure AlertIfNotBackground which checks to see that it is indeed in the backgound and if not issues a message(s).

Not having to hardcode each call with the caller's name would be a big help! Being able to include a more complete callstack/traceback would be sublime :slight_smile:

Kind regards,
Randal

[Edit]
I should add that the convention I am trying to use is to

  1. preface the name of any procedure which must run in the background with "bg_". I have about 13 such procedures.

  2. If a "bg_" procedure is called from the UI it is called using the itoo.CallBackgroundProcedure.

  3. If a "bg_" procedure is called from within an enclosing "bg_" procedure, it is called directly.

The caller checks (AlertIfNotBackground) are an added development / debug feature to verify that I do not violate my scheme.

Hi Randal, I'll try to get back to this feature once I'm a bit free. Do message/ping me a week or so later if I forget.

Many thanks :ok_hand: !!!
-Randal