Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

v1.0.47 released: Stdlib, RegisterCallback, NumGet/Put


  • Please log in to reply
54 replies to this topic
TL
  • Members
  • 21 posts
  • Last active: Dec 16 2018 02:33 PM
  • Joined: 01 Nov 2006
Thanks. You provided just the insight I was looking for.
TL

  • Guests
  • Last active:
  • Joined: --
Is it planned to support direct invoking like
testa()
{
    MsgBox, testa
}

("test" . "a")()


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
If I think of a simple way to implement it, I might. For now it seems of too little benefit.

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006

Is it planned to support direct invoking like

testa()
{
    MsgBox, testa
}

("test" . "a")()


I am not understanding this. How would this work?

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Not much could be saved with this alone, but it is hard to understand, what is intended:
fun := "test" . "a"

%fun%()
I proposed long ago to use square brackets to force evaluation inside. That is easier to the eyes.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Thanks for the update :) . Now... to find those test scripts I had put aside that would benefit from dynamic function calling...

trik
  • Members
  • 1317 posts
  • Last active: Jun 11 2010 11:48 PM
  • Joined: 15 Jul 2007
@ corrupt

Loop, 4 {
   Func%A_Index%()
}

Func1() {
   MsgBox, Func 1
}

Func2() {
   MsgBox, Func2
}

Func3() {
   MsgBox, Func3
}

Func4() {
   MsgBox, Func4
}

Something that would require calling multiple functions.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
would we have a Isfunction() ?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Even if you know a function exists, the call may fail because of incorrect parameter count or use of ByRef. I haven't thought of a (syntactically) good solution yet.

If you are using dynamic calls to implement "callbacks" which are required to not use ByRef, you may use RegisterCallback to validate the function:
GetFuncParamCount(FuncName, ByRef MinParams, ByRef MaxParams)
{   ; Fails for functions which are built-in or use ByRef.
    if cb := RegisterCallback(FuncName)
    {
        MinParams := NumGet(NumGet(cb+28)+16)
        MaxParams := NumGet(NumGet(cb+28)+12)
        DllCall("GlobalFree","uint",cb)
        return true
    }
    return false
}
If you don't need to validate before calling the function, you may use the following. By setting a byte within the string to 0, you can unambiguously detect failure:
F = TestFunc
NumPut(0,r:=1,0,"char")
    , r:=%F%() ; Must be part of a multi-statement expression.
if StrLen(r)=1 && !NumGet(r,0,"char")
    MsgBox, r contains a value that could not ever be returned by a function
            , so the call must have failed.


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
The second one is nice.. Thanks Lexikos. :)