| View previous topic :: View next topic |
| Author |
Message |
TL
Joined: 01 Nov 2006 Posts: 20
|
Posted: Fri Mar 14, 2008 2:15 am Post subject: |
|
|
Thanks. You provided just the insight I was looking for.
TL |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Mar 14, 2008 3:27 am Post subject: |
|
|
Is it planned to support direct invoking like
| Code: | testa()
{
MsgBox, testa
}
("test" . "a")() |
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Fri Mar 14, 2008 9:11 am Post subject: |
|
|
| If I think of a simple way to implement it, I might. For now it seems of too little benefit. |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Fri Mar 14, 2008 10:22 pm Post subject: |
|
|
| 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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Fri Mar 14, 2008 10:31 pm Post subject: |
|
|
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 |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sun Mar 16, 2008 7:23 am Post subject: |
|
|
Thanks for the update . Now... to find those test scripts I had put aside that would benefit from dynamic function calling... |
|
| Back to top |
|
 |
trik
Joined: 15 Jul 2007 Posts: 1320
|
Posted: Sun Mar 16, 2008 8:02 pm Post subject: |
|
|
@ 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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Fri Apr 04, 2008 9:04 pm Post subject: |
|
|
| would we have a Isfunction() ? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Sat Apr 05, 2008 12:15 am Post subject: |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sat Apr 05, 2008 4:16 am Post subject: |
|
|
The second one is nice.. Thanks Lexikos.  |
|
| Back to top |
|
 |
|