#include <GUIConstantsEx.au3>
SetCurrentFuncName()
Global $sCurrentFuncName = ""
$hGUI = GUICreate("SetCurrentFuncName Demo", 300, 200)
$nButton = GUICtrlCreateButton("Call Funcs", 20, 40, 60, 20)
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $nButton
_MyFunc()
_OtherFunc()
_NextFunc()
EndSwitch
WEnd
Func _MyFunc()
MsgBox(64, 'FuncName', $sCurrentFuncName)
EndFunc
Func _OtherFunc()
MsgBox(64, 'FuncName', $sCurrentFuncName)
EndFunc
Func _NextFunc()
MsgBox(64, 'FuncName', $sCurrentFuncName)
EndFunc
Func SetCurrentFuncName()
If @Compiled Or StringInStr($CmdLineRaw, '/Restarted') Then Return
Local $sRead = FileRead(@ScriptFullPath)
Local $aFuncs = StringRegExp($sRead, '(?i)\r?\n\h*func\h+(\w+)\h*\(.*?\)\r?\n', 3)
$sRead = StringRegExpReplace($sRead, '(\r?\n?\t*SetCurrentFuncName\(\)\r?\n)(?:\t*Global \$sCurrentFuncName = ""\r?\n?)?', '\1Global $sCurrentFuncName = ""' & @CRLF, 1)
For $i = 0 To UBound($aFuncs)-1
If $aFuncs[$i] = "SetCurrentFuncName" Then
ContinueLoop
EndIf
$sRead = StringRegExpReplace($sRead, _
'(?i)(\r?\n\h*func\h+' & $aFuncs[$i] & '\h*\(.*\)\r?\n)\t*(?:\$sCurrentFuncName = "' & $aFuncs[$i] & '"|(.*?))\r?\n', _
'\1' & @TAB & '$sCurrentFuncName = "' & $aFuncs[$i] & '"' & @CRLF & '\2')
Next
$hFile = FileOpen(@ScriptFullPath, 2)
FileWrite($hFile, $sRead)
FileClose($hFile)
ShellExecute(@ScriptFullPath, $CmdLineRaw & ' /Restarted', @ScriptDir)
Exit
EndFunc