yeah, u missed the part where it says
Other properties and methods are inherited from
Func, but
do not reflect the properties of the target function or method (which is not required to be implemented as a function). The
BoundFunc acts as an anonymous variadic function with no other formal parameters, similar to the fat arrow function below:
Code: Select all
Func_Bind(fn, bound_args*) {
return (args*) => (args.InsertAt(1, bound_args*), fn(args*))
}
u can recover the target function and do some math to figure what its "new MinParams" count should be, and then override BoundFunc's methods to use that procedure instead:
Code: Select all
#Requires AutoHotkey v2.0-beta.4
TheFunc(param1, param2) {
MsgBox("TheFunc: " param1)
}
f := TheFunc.Bind(42)
pf := ObjPtr(f)
BoundParamsArray := ObjFromPtrAddRef(NumGet(pf, (A_PtrSize = 4) ? 44 : 72, 'Ptr'))
WrappedTheFunc := ObjFromPtrAddRef(NumGet(pf, (A_PtrSize = 4) ? 36 : 56, 'Ptr'))
actuallyBoundParamsCount := 0
Loop BoundParamsArray.Length
if BoundParamsArray.Has(A_Index) ; handles func.Bind(, , , 42) type scenarios
++actuallyBoundParamsCount
actualMinParams := WrappedTheFunc.MinParams - actuallyBoundParamsCount
MsgBox actualMinParams
this isnt an exhaustive implementation, u still need to handle BoundFuncs of BoundFuncs, methods, closures and probably other edge cases i havent yet thought of