JoGa Posted September 30, 2010 Share Posted September 30, 2010 Is there a way to get the name of the function autoit is currently executing? Or even better: in a Func, can I get the name of the calling func? Jo Link to comment Share on other sites More sharing options...
water Posted September 30, 2010 Share Posted September 30, 2010 No, as far as I know. But you can define two global variables that hold the name of the current and calling function and set them accordingly. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Mat Posted September 30, 2010 Share Posted September 30, 2010 I'd do it like this: expandcollapse popup#include <Array.au3> Global $aStack[1] = [0] _MyFun() Func _MyFun() _EnterFunc("_MyFun") MsgBox(0, _GetCurrentFunc(), "Called by: " & _GetCallingFunc()) _MyFun2() Return _Return() EndFunc Func _MyFun2() _EnterFunc("_MyFun2") MsgBox(0, _GetCurrentFunc(), "Called by: " & _GetCallingFunc()) Return _Return() EndFunc Func _GetCurrentFunc() If $aStack[0] = 0 Then Return "" Return $aStack[$aStack[0]] EndFunc Func _GetCallingFunc() If $aStack[0] <= 1 Then Return "" Return $aStack[$aStack[0] - 1] EndFunc Func _EnterFunc($sName) _ArrayAdd($aStack, $sName) $aStack[0] += 1 EndFunc Func _Return($sRet = 0, $iExt = 0, $iErr = 0) _ArrayDelete($aStack, $aStack[0]) $aStack[0] -= 1 Return SetError($iErr, $iExt, $sRet) EndFunc Whenever you enter a function that is to be included in the stack, use _EnterFunc() with the name of the function, and whenever you leave call the _Return function. _ArrayDisplay($aStack) will show you the whole stack. AutoIt Project Listing Link to comment Share on other sites More sharing options...
JoGa Posted September 30, 2010 Author Share Posted September 30, 2010 I'd do it like this: expandcollapse popup#include <Array.au3> Global $aStack[1] = [0] _MyFun() Func _MyFun() _EnterFunc("_MyFun") MsgBox(0, _GetCurrentFunc(), "Called by: " & _GetCallingFunc()) _MyFun2() Return _Return() EndFunc Func _MyFun2() _EnterFunc("_MyFun2") MsgBox(0, _GetCurrentFunc(), "Called by: " & _GetCallingFunc()) Return _Return() EndFunc Func _GetCurrentFunc() If $aStack[0] = 0 Then Return "" Return $aStack[$aStack[0]] EndFunc Func _GetCallingFunc() If $aStack[0] <= 1 Then Return "" Return $aStack[$aStack[0] - 1] EndFunc Func _EnterFunc($sName) _ArrayAdd($aStack, $sName) $aStack[0] += 1 EndFunc Func _Return($sRet = 0, $iExt = 0, $iErr = 0) _ArrayDelete($aStack, $aStack[0]) $aStack[0] -= 1 Return SetError($iErr, $iExt, $sRet) EndFunc Whenever you enter a function that is to be included in the stack, use _EnterFunc() with the name of the function, and whenever you leave call the _Return function. _ArrayDisplay($aStack) will show you the whole stack. Thanks for your suggestion Link to comment Share on other sites More sharing options...
Tvern Posted September 30, 2010 Share Posted September 30, 2010 Keep in mind that ArrayAdd and ArrayDelete use ReDim. Redim is fairly slow, so if you are doing lots of ReDims per second it could slow down the script by a noticable amount. As an alternative you could make the array fixed size. According to the helpfile the limit for recursive function calls is 5100 levels, so 5101 indices should be enough. It's a little wasted memory, but if you are calling allot of functions per second it might make a difference. This all depends on how often logged functions are called though. Here is a modified example with fixed array size: expandcollapse popupGlobal $aStack[5101] _MyFun() Func _MyFun() _EnterFunc("_MyFun") MsgBox(0, _GetCurrentFunc(), "Called by: " & _GetCallingFunc()) _MyFun2() Return _Return() EndFunc Func _MyFun2() _EnterFunc("_MyFun2") MsgBox(0, _GetCurrentFunc(), "Called by: " & _GetCallingFunc()) Return _Return() EndFunc Func _GetCurrentFunc() If $aStack[0] = 0 Then Return "" Return $aStack[$aStack[0]] EndFunc Func _GetCallingFunc() If $aStack[0] <= 1 Then Return "" Return $aStack[$aStack[0] - 1] EndFunc Func _EnterFunc($sName) $aStack[0] += 1 $aStack[$aStack[0]] = $sName EndFunc Func _Return($sRet = 0, $iExt = 0, $iErr = 0) $aStack[$aStack[0]] = "" $aStack[0] -= 1 Return SetError($iErr, $iExt, $sRet) EndFunc If you are just trying to trace the source of an error you can use "Trace: Add Func Trace Lines" from the tools menu in SciTE4AutoIt3, which will print funtion calls to the console. Link to comment Share on other sites More sharing options...
Mat Posted September 30, 2010 Share Posted September 30, 2010 I'd place a smaller limit I think, 5101 seems a bit ott. I might look at Trace: Add Func Trace Lines and see if I can get it to add all the stack bits like this, that would be interesting, or you provide the information to an external debugger... AutoIt Project Listing Link to comment Share on other sites More sharing options...
Tvern Posted September 30, 2010 Share Posted September 30, 2010 I just used 5101 because that's the limit for autoit recursion, but any sane scripter wouldn't go near that limit. How about this as a hybrid solution? You keep the speed as long as you don't exceed a predicted maximum amount of recursion and you don't have a big nearly empty array in use: expandcollapse popupGlobal $iRecuse = 10 ;expected maximum recursion Global $aStack[$iRecuse + 1] _MyFun() Func _MyFun() _EnterFunc("_MyFun") MsgBox(0, _GetCurrentFunc(), "Called by: " & _GetCallingFunc()) _MyFun2() Return _Return() EndFunc Func _MyFun2() _EnterFunc("_MyFun2") MsgBox(0, _GetCurrentFunc(), "Called by: " & _GetCallingFunc()) Return _Return() EndFunc Func _GetCurrentFunc() If $aStack[0] = 0 Then Return "" Return $aStack[$aStack[0]] EndFunc Func _GetCallingFunc() If $aStack[0] <= 1 Then Return "" Return $aStack[$aStack[0] - 1] EndFunc Func _EnterFunc($sName) $aStack[0] += 1 If $aStack[0] > $iRecuse Then ReDim $aStack[$aStack[0]+1] $aStack[$aStack[0]] = $sName EndFunc Func _Return($sRet = 0, $iExt = 0, $iErr = 0) If $aStack[0] > $iRecuse Then ReDim $aStack[$aStack[0]] Else $aStack[$aStack[0]] = "" EndIf $aStack[0] -= 1 Return SetError($iErr, $iExt, $sRet) EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now