Procedure/Function introspection

Hi,

Is it possible to determine the name of a procedure or function that is running?
(For you C programmers, something akin to the __FUNCTION__ macro)


I’ve gone through Info("ProcedureStack"), but it, unfortunately, does not include the original caller in its stack.

Scenario #1

If:
   ProcedureA calls ProcedureB
Then:
   Info("ProcedureStack") in ProcedureB returns "ProcedureB"

Expected result: Info("ProcedureStack"), when called from ProcedureB, includes ProcedureA and ProcedureB.

Scenario #2

If:
  ProcedureA calls ProcedureB which calls ProcedureC
Then:
  Info("ProcedureStack") in ProcedureC, returns "ProcedureB" and "ProcedureC"

Expected result: Info("ProcedureStack"), when called from ProcedureC, includes ProcedureA, ProcedureB, and ProcedureC.


Unfortunately, CallingProcedure() also does not return what’s expected.

Scenario #3

If:
  ProcedureA calls ProcedureB
Then:
  CallingProcedure() in ProcedureB returns an empty string

Expected result: CallingProcedure(), when called from ProcedureB, returns ProcedureA.

Scenario #4

If:
  ProcedureA calls ProcedureB, which calls ProcedureC
Then:
  CallingProcedure() in ProcedureC returns "ProcedureB"

Expected result: Exactly what happens. (IOW, this works)


Next to “CallingProcedure()”, it’d be nice to have something like “CurrentProcedure()” that returns info about the currently running procedure or function.

Why would I want this? Glad you asked … :wink:

I’ve got a very simple logging function that writes information to a log file as the program runs.
It would be nice if each statement could automagically write out the procedure name without requiring the calling procedure to provide the procedure/function name in a FileGlobal variable.

Thanks for listening … :slight_smile:

Yes, it would. That’s why Panorama X includes this:

Also, in Panorama X the info(“procedurestack”) function works correctly, as does callingprocedure(. Sadly, I never could get these introspection features to work reliably in Panorama 6, it turned out that introspection just couldn’t be successfully grafted on to the very byzantine code that the older version used for running procedures, though I tried very very hard to do so. In Panorama X introspection was designed for and built in from the start.

Sorry this isn’t immediately useful to you, but hopefully at least you’ll find it somewhat educational!

I suspected it was something like that.

Thanks for the history lesson.
As always, very educational! :slight_smile:

In pan6 I had a global called vgcurrentprocedure and updated it with hard code at the start of every procedure. Worked like a dream.

chris

1 Like

Chris,

Yeah. A bit crude, but very effective! :slight_smile:

Thanks,

– Mark