AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

v1.0.47 released: Stdlib, RegisterCallback, NumGet/Put
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Announcements
View previous topic :: View next topic  
Author Message
TL



Joined: 01 Nov 2006
Posts: 9

PostPosted: Fri Mar 14, 2008 3:15 am    Post subject: Reply with quote

Thanks. You provided just the insight I was looking for.
TL
Back to top
View user's profile Send private message
Guest






PostPosted: Fri Mar 14, 2008 4:27 am    Post subject: Reply with quote

Is it planned to support direct invoking like
Code:
testa()
{
    MsgBox, testa
}

("test" . "a")()
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 2359
Location: Australia, Qld

PostPosted: Fri Mar 14, 2008 10:11 am    Post subject: Reply with quote

If I think of a simple way to implement it, I might. For now it seems of too little benefit.
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 379
Location: Berlin

PostPosted: Fri Mar 14, 2008 11:22 pm    Post subject: Reply with quote

Anonymous wrote:
Is it planned to support direct invoking like
Code:
testa()
{
    MsgBox, testa
}

("test" . "a")()


I am not understanding this. How would this work?
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 3877
Location: Pittsburgh

PostPosted: Fri Mar 14, 2008 11:31 pm    Post subject: Reply with quote

Not much could be saved with this alone, but it is hard to understand, what is intended:
Code:
fun := "test" . "a"
%fun%()
I proposed long ago to use square brackets to force evaluation inside. That is easier to the eyes.
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2328

PostPosted: Sun Mar 16, 2008 8:23 am    Post subject: Reply with quote

Thanks for the update Smile . Now... to find those test scripts I had put aside that would benefit from dynamic function calling...
Back to top
View user's profile Send private message Visit poster's website
Ian



Joined: 15 Jul 2007
Posts: 1077
Location: Enterprise, Alabama

PostPosted: Sun Mar 16, 2008 9:02 pm    Post subject: Reply with quote

@ corrupt

Code:
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.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5298

PostPosted: Fri Apr 04, 2008 10:04 pm    Post subject: Reply with quote

would we have a Isfunction() ?
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2359
Location: Australia, Qld

PostPosted: Sat Apr 05, 2008 1:15 am    Post subject: Reply with quote

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:
Code:
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:
Code:
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.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5298

PostPosted: Sat Apr 05, 2008 5:16 am    Post subject: Reply with quote

The second one is nice.. Thanks Lexikos. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Announcements All times are GMT
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
Jump to:  
You cannot post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group