Test Build - Func.Bind( . . . ) enhancments

Propose new features and changes
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Test Build - Func.Bind( . . . ) enhancments

28 Feb 2015, 04:52

So the latest test build(1.1.19.03-37+gd7b054a) implemented Func.Bind(args*). It's already great as it is but perhaps the following would make it even better:
Currently, arguments passed to the bound object/function are appended at the end, so how about treating omitted arguments(during binding) as placeholders for arguments to be passed when calling the bound object. Imaginary usage below:

Code: Select all

WM_CLOSE := Func("DllCall").Bind("SendMessage", "Ptr", , "UInt", 0x0010, "Ptr", 0, "Ptr", 0) ; 3rd argument omitted
WM_CLOSE.Call(hWnd) ; each passed argument is inserted at the index of the omitted argument(s), the remainder will be appended if args > omitted_args

RECT_GetLeft := Func("NumGet").Bind(, 0, "Int") ; first argument omitted
left := RECT_GetLeft.Call(&RECT) ; must pass address, ByRef not supported  I assume
I'm not sure if it's possible or impossible to implement this but I thought I'd give it a try.
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Test Build - Func.Bind( . . . ) enhancments

28 Feb 2015, 20:13

It is possible, but would be more complicated. I might try it.

Currently your code creates a sparse array of args, like ["SendMessage", "Ptr", , "UInt", ...]. When calling the function, the parameter list becomes something like DllCall(bound_args*, supplied_args*) (except that AutoHotkey doesn't support that). So binding (a, , c) and then calling with (d) produces (a, , c, d), which might be meaningful to some user-defined functions. Your request would make it like (a, d, c); I don't know if that's necessarily intuitive.
GeekDude
Posts: 853
Joined: 02 Oct 2013, 22:13

Re: Test Build - Func.Bind( . . . ) enhancments

28 Feb 2015, 20:15

I think it may be important to make sure to differentiate between blank parameters and omitted parameters. So , "", must be different from ,,.
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Test Build - Func.Bind( . . . ) enhancments

28 Feb 2015, 20:20

It is. To minimize code size, Func.Bind() internally stores the parameters as a normal array-object. It effectively calls Array(...), so Func.Bind(a, , c) creates an array identical to [a, , c], which is identical to {1: a, 3: c}.
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Test Build - Func.Bind( . . . ) enhancments

13 Oct 2019, 06:28

Better late than never... this was implemented in v2.0-a106.
toralf
Posts: 636
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Test Build - Func.Bind( . . . ) enhancments

17 Oct 2019, 21:54

That sounds interesting.
Thanks for comeback to such old suggestions and working on them.

I assume is is robust, e.g. when during binding a sparse array of parameters is provided (3rd and 5th Parameter being left out of a 6 parameters) and during call 4 extra parameters are provided, that the final call to the bound function is a “mixture” of the two arrays resulting in non-sparse array.
Say ArraayBound := [a, b, , d, , f] and CallArray := [c, e, g, h] results in FinalArray := [a, b, c, d, e, f, g, h]
ciao
toralf

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 12 guests