[v2] Zero-length variadic argument should not trigger an error message Topic is solved
[v2] Zero-length variadic argument should not trigger an error message
If an unpacked array is passed to a function, and the array has a length of zero, it should not trigger the "too many params passed to function" error message.
Re: [v2] Zero-length variadic argument should not trigger an error message
Are you mistaken? V1 has this error.
Re: [v2] Zero-length variadic argument should not trigger an error message
Code: Select all
; v1
1:: Highlight.StrUpper()
StrUpper(s) {
StringUpper _s, s
return _s
}
class Highlight extends Highlight.Delegate {
class Delegate {
__Call(function, args*) {
IsObject(function)
? Paste(function.call("", Copy(), args*))
: Paste(%function%(Copy(), args*))
}
}
}
Copy() {
Clip0 := ClipboardAll
Clipboard := "" ; Must start off blank for detection to work
Send ^c
ClipWait 0.5
if !ErrorLevel
s := Clipboard
Clipboard := Clip0
VarSetCapacity(Clip0, 0) ; Free memory
return s ; Allows the empty string ("") for side-effects
}
Paste(s) {
if (s == "")
return
Clip0 := ClipboardAll
Clipboard := s
Send ^v
Sleep 50 ; Don't change Clipboard while it is pasted! (Sleep > 0)
Clipboard := Clip0 ; Restore original Clipboard
VarSetCapacity(Clip0, 0) ; Free memory
}
Re: [v2] Zero-length variadic argument should not trigger an error message Topic is solved
You both wrote words which are true, but with mistaken implications.
@thqby
Yes, v1 has this error, but it is never triggered by a dynamic or variadic call. The total parameter count is allowed to exceed MaxParams at runtime in v1.
@iseahound
You are correct that the condition you described should not trigger that error message. And it doesn't.
The non-dynamic calls trigger a load-time error in v2.0-a122 and earlier (even with syntax changed to suit the version) because the parser saw a non-empty parameter at an invalid position. It is permitted in later versions because the function parameters are validated at a later stage.
However, unset elements at the end of the array still count toward the parameter validation. This is by design.
I would guess that you might have been using the wrong syntax for __Call in v2, and ended up with a variadic Array that was not empty because it contained an Array of parameters.
@thqby
Yes, v1 has this error, but it is never triggered by a dynamic or variadic call. The total parameter count is allowed to exceed MaxParams at runtime in v1.
@iseahound
You are correct that the condition you described should not trigger that error message. And it doesn't.
Code: Select all
#Requires AutoHotkey v2.0-beta
nondynamic0([]*)
nondynamic0() {
MsgBox("works")
}
nondynamic1(1, []*)
nondynamic1(n) {
MsgBox("works")
}
dynamic := nondynamic0
dynamic(A_Args*)
dynamic := nondynamic1
dynamic(1, A_Args*)
However, unset elements at the end of the array still count toward the parameter validation. This is by design.
Code: Select all
noargs([unset]*)
noargs() => MsgBox("is not called")
Re: [v2] Zero-length variadic argument should not trigger an error message
Okay, I see that the syntax for meta-functions has changed from v1 to v2.
Previously I had to collect all the values into an array myself:
__Call(name, params*) ; v1 https://www.autohotkey.com/docs/Objects.htm#Meta_Functions
__Call(name, params) ; v2 https://lexikos.github.io/v2/docs/Objects.htm#Meta_Functions
Previously I had to collect all the values into an array myself:
__Call(name, params*) ; v1 https://www.autohotkey.com/docs/Objects.htm#Meta_Functions
__Call(name, params) ; v2 https://lexikos.github.io/v2/docs/Objects.htm#Meta_Functions
Code: Select all
class Highlight {
static __Call(name, params) => Paste(%name%(Copy(), params*))
}
1:: Highlight.Notepad()
2:: Highlight.AutoHotkey(250, "string")
3:: Highlight.DuckDuckGo()
4:: Highlight.Translate()
; This is a wrapper class.
; Use this class with dot notation without the first argument
; as in Highlight.myFunc(param1, param2, ...)
; The first argument will be the highlighted text.
Copy() {
s := ""
ClipSaved := ClipboardAll()
A_Clipboard := "" ; Must start off blank for detection to work
Send "^c"
if ClipWait(0.5)
s := A_Clipboard
A_Clipboard := ClipSaved
return s ; Allows the empty string ("") for side-effects
}
Paste(s) {
if (s == "")
return
ClipSaved := ClipboardAll()
A_Clipboard := s
Send "^v"
Sleep 50 ; Don't change Clipboard while it is pasted! (Sleep > 0)
A_Clipboard := ClipSaved ; Restore original Clipboard
}
AutoHotkey(s, wait := 1000, extra := true) {
MsgBox "function params: " wait ", " extra
Run "https://www.autohotkey.com/docs/AutoHotkey.htm"
Sleep wait
Send "!s"
Paste(s)
Send "{Enter}"
}
DuckDuckGo(s) {
Run "https://duckduckgo.com/?q=\" s
}
Notepad(s) {
Run "notepad.exe",,, &_pid
WinWait "ahk_pid" _pid
return s
}
Translate(s) {
Run "https://translate.google.com/?sl=auto&tl=en&text=" s
}
Who is online
Users browsing this forum: No registered users and 24 guests