Page 1 of 1

Discovery of calling routine

Posted: Tue Jun 19, 2018 9:44 pm
by mvillion
If I have a script and it calls a function, can the function know what script called it?
This would be very useful in debugging.

Re: Discovery of calling routine

Posted: Tue Jun 19, 2018 9:55 pm
by jmburnod
Hi,
You may use "executionContexts".
Best regards
Jean-Marc

Re: Discovery of calling routine

Posted: Tue Jun 19, 2018 9:55 pm
by Klaus
Please check "ExecutionContexts" in the dictionary, I think this is what you are looking for!

Re: Discovery of calling routine

Posted: Tue Jun 19, 2018 11:38 pm
by mvillion
Hi

Close but not quite

Consider this

Code: Select all

on Command01
 put theFunction() into theAnswer
end Command01

on Command02
 put theFunction() into theAnswer
end Command2

function theFunction
 return ThisText
end function
Can 'thefunction' know who called it?

Re: Discovery of calling routine

Posted: Wed Jun 20, 2018 7:05 am
by jmburnod
Hi mvillion,
What about executionContexts ?

Code: Select all

function theFunction
  put item -2 of line -2 of the executionContexts into tHandler
 return ThisText && tHandler
end function

Re: Discovery of calling routine

Posted: Wed Jun 20, 2018 9:16 am
by mvillion
Perfect. Thanks

Re: Discovery of calling routine

Posted: Wed Jun 20, 2018 9:31 am
by Klaus
You're welcome! 8)