Jump to content

Obtaining the name of the current function?


Recommended Posts

Is there a way to obtain the name of the current function? Being able to do so would simplify many parts of my scripts. For instance, for HotKeySet I would be able to make a generic block of code to release and reacquire a hotkey rather than having to type a new function name for each one.

Edited by Christopher Blue
Link to comment
Share on other sites

I read it about 5 times and didn't get it.

Instead of this:

Func HotKeyFunc()

      Dim $c = @HotKeyPressed
   
      If (HotKeyShouldBePassedOn()) Then
         HotKeySet($c)
         Send($c)
         HotKeySet($c, "HotKeyFunc")
         Return
      EndIf
EndFunc

I could write this:

Func HotKeyFunc()

      Dim $c = @HotKeyPressed
   
      If (HotKeyShouldBePassedOn()) Then
         HotKeySet($c)
         Send($c)
         HotKeySet($c, CurrentFunctionName())
         Return
      EndIf
EndFunc

It is a small difference but it would be one less place for me to make a typo or even worse, accidently put in the wrong function name.

Edited by Christopher Blue
Link to comment
Share on other sites

Still not quite getting the big picture here, but, couldn't you just have your functions set a $var and pass it as an argument through your HotKeyFunc()?

Func HotKeyFunc($func_var)

      Dim $c = @HotKeyPressed
  
      If (HotKeyShouldBePassedOn()) Then
         HotKeySet($c)
         Send($c)
         HotKeySet($c, $func_var)
         Return
      EndIf
EndFunc
Link to comment
Share on other sites

Use with ctrl+c...

$func = 'func1'

HotKeySet('^c', $func)
HotKeySet('{escape}', 'quit')

Func func1($func)
    $key = @HotKeyPressed
    $func = 'func2'
    HotKeySet($key, $func)
    MsgBox(0, '', 'func 1')
EndFunc

Func func2($func)
    $key = @HotKeyPressed
    $func = 'func1'
    HotKeySet($key, $func)
    MsgBox(0, '', 'func 2')
EndFunc

Func quit()
    Exit
EndFunc

While 1
    Sleep(100)
WEnd
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...