BoundFunc Object, .Bind() parameter variadic syntax: Preserve function paramter type

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

BoundFunc Object, .Bind() parameter variadic syntax: Preserve function paramter type

12 Nov 2019, 09:25

Hello,

suppose I have a string like (that's how I get the function parameters from my regex)

Code: Select all

sParams := "true, 123, ""Hello""   "
which consists of an boolean, integer and string value.
After parsing that string I get an array of parameter values:

Code: Select all

aParams := []
Loop, Parse, sParams, `, , %A_Space%
{
  sParam := A_LoopField
  aParams.Push( sParam ) 
}
Then I want to bind these values to a non-variadic function with variadic syntax.
That works, but how can I preserve the function parameter types?


Test code:

Code: Select all

sFuncName := "FuncTest"
sParams := "true, 123, ""Hello""   " ; that's how I get the function parameters from my regex

aParams := []
Loop, Parse, sParams, `, , %A_Space%
{
  sParam := A_LoopField
  aParams.Push( sParam )

}

oFunc := Func( sFuncName ).Bind( aParams* )
oFunc.Call()


FuncTest( p_bVal, p_iVal, p_sVal)
{
  MsgBox, % "bVal = " p_bVal "`niVal = " p_iVal "`nsVal = " p_sVal
}

Many thanks and greetings
hotkeyguy
User avatar
Chunjee
Posts: 1429
Joined: 18 Apr 2014, 19:05
Contact:

Re: BoundFunc Object, .Bind() parameter variadic syntax: Preserve function paramter type

13 Nov 2019, 07:42

"I have a function that takes 3 arguments, I want to give it an array of arguments as though it was variadic, which it isn't"

Doesn't seem possible to me. Have a thread bump though.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: BoundFunc Object, .Bind() parameter variadic syntax: Preserve function paramter type

13 Nov 2019, 10:14

Code: Select all

theFunction(myArrayOfParams*)
don't know what u mean by preserve the types. if u expect the bool param to say "true" in the msgbox instead of 1, can't be done. AHK doesn't have bools.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: BoundFunc Object, .Bind() parameter variadic syntax: Preserve function paramter type

13 Nov 2019, 19:44

Perhaps something like this:

Code: Select all

aParams := []
sParams := "true, 123, ""Hello"""
MsgBox, % sParams ;true, 123, "Hello"

for vKey, vValue in StrSplit(sParams, ", ")
{
	if RegExMatch(vValue, "s)^\x22.*\x22$")
		aParams.Push("" SubStr(vValue, 2, -1))
	else if (vValue = "true")
		aParams.Push(1)
	else if (vValue = "false")
		aParams.Push(0)
	else if vValue is number
		aParams.Push(0+vValue)
	else
		MsgBox, % "unhandled: " vValue
}

vOutput := ""
for vKey, vValue in aParams
	vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hiahkforum and 356 guests