ahk[Post]Function parameters bug

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

ahk[Post]Function parameters bug

24 Aug 2018, 10:20

I didn't thoroughly check the forums, but I didn't see anything about it in the _H forum anyway. Originally, I had tried sending varadic parameters via DllCall, which didn't work, and I'm assuming there's not a way to get that working. But, I just noticed that you can't use ahkPostFunction on a function that uses a varadic parameter. I tried and it crashed. So then I compromised and tried using something like func(var,o1:="",o2=""). That also doesn't work; say if you send it 2 parameters, the third (o2) will contain "Str". If you leave two optional parameters blank, it will crash. I finally settled for func(var,o1,2) and just sent blank/empty variables when they weren't needed.

My question is: is this unavoidable? Could varadic/optional function parameters possibly work?
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: ahk[Post]Function parameters bug

24 Aug 2018, 12:54

Unfortunately not.
However you can share function objects to call the function:

Code: Select all

ahk:=AhkThread("
(
#Persistent
SetBatchlines, -1
cFun:=Func(""fun"")
pFun:=&cFun
fun(var*){
	MsgBox `% var.1 ""``n"" var.2
}
)")

cFun:=Object(ahk.ahkFindFunc("fun"))

; you can also use Alias
;    Alias(cFun,ahk.ahkgetvar("cFun",1)) 

;  or use a pointer
;    cFun:=Object(ahk.ahkgetvar("pFun"))
cFun.Call("a","b")
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: ahk[Post]Function parameters bug

24 Aug 2018, 13:55

That's what I thought. Though, what you suggested is pretty much perfect for my use case, so I'll try doing that. Thank you!
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 17 guests