Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

v1.0.47 released: Stdlib, RegisterCallback, NumGet/Put


  • Please log in to reply
54 replies to this topic
Thalon
  • Members
  • 641 posts
  • Last active: Jan 02 2017 12:17 PM
  • Joined: 12 Jul 2005
So.. I hope the next release will take some time.
I had some work to merge the changed parts into the existing german translation :lol:

Just joking.
Thanks for this new version!

Thalon

ryebread
  • Members
  • 4 posts
  • Last active: Nov 14 2011 05:27 AM
  • Joined: 11 Dec 2006
big release Chris, congratulations!
thx :D

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Here are the changes for v1.0.47.06:

Fixed crash when a function was called concurrently with an optional ByRef parameter omitted by one thread but not omitted by the other. [thanks DeathByNukes]

Fixed "Menu, Tray, MainWindow" to enable the menu items in the main window's View menu. [thanks lexiKos]

Added dynamic function calling. [developed by lexiKos]
Description: A function (even a built-in function) may be called dynamically via percent signs. For example, %Var%(x, "fox") would call the function whose name is contained in Var. Similarly, Func%A_Index%() would call Func1() or Func2(), etc., depending on the current value of A_Index. The called function's definition must exist explicitly in the script, either via #Include or a non-dynamic call to a library containing the function. If the function does not exist -- or if the wrong number or type of parameters is passed to it -- the expression containing the call produces an empty string.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Thanks for the update.. and nice to see you back in action Mr.Chris
Dynamic function Calling! Ooh.. Thanks lexiKos :D

daonlyfreez
  • Members
  • 995 posts
  • Last active: Jan 23 2013 08:16 AM
  • Joined: 16 Mar 2005
Excellent! Especially the dynamic function calling 8)

And, also from me: good to see you are still around, Chris. I hope you can keep up the good work somehow. :)
Posted Image mirror 1mirror 2mirror 3ahk4.me • PM or Posted Image

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
Oh great thx, long waited internal support of dynamic function call. Go(o)d to see you back, Chris.

lexikos, your`re great!!

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

lexikos, your`re great!!

...but not infallible. ;) Expect a bug-fix release some time in the future. I've "submitted" the fix already, but until AutoHotkey is updated, avoid doing things like this:
f = ; empty...
%f%() ; crashes.
VarSetCapacity(f, 255, Asc("f")) ; too long...
%f%() ; crashes.

Similarly, Func%A_Index%() would call the function whose name is stored in the specified array element.

I think this is misleading: "Func" actually forms part of the name. Func%A_Index%() calls Func1(), Func2(), etc. and does not touch the variables (array elements) named Func1, Func2, FuncN...

I'm not sure it is worth mentioning in the help file, but failure can be detected by taking advantage of the difference between standalone assignment and multi-statement expressions:
f = InvalidFunc

; Standalone assignment: if the dynamic call fails,
;   the expression results in a blank value, which is assigned.
result := "FAIL" ; This is overwritten.
result := %f%()

MsgBox %result%

; Multi-statement expression: if the dynamic call fails,
;   the second assignment never even occurs.
result := "FAIL", result := %f%()

MsgBox %result%


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

Similarly, Func%A_Index%() would call the function whose name is stored in the specified array element.

I think this is misleading: "Func" actually forms part of the name. Func%A_Index%() calls Func1(), Func2(), etc. and does not touch the variables (array elements) named Func1, Func2, FuncN...

Thanks. I've fixed the documentation.

Rajat as guest
  • Guests
  • Last active:
  • Joined: --
Thanks for the update Chris and lexiKos!
and Chris, we all missed you.
I'm glad to see you back.

Zoulou
  • Guests
  • Last active:
  • Joined: --
Exactly the same as Rajat.
Just a little noob question : please Chris, do you continue to work on V2 of AHK, and, if it is the case, do you think that we will see it in few/a lot of months ?
Thanks again :D :D :D

toralf not loged in
  • Guests
  • Last active:
  • Joined: --
Hi,
And thanks a lot for the dynamic function calls. Even that I stoped coding, I still have an eye on AHK.
Greetings.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Thanks lexikos. Finaly offical recognition for your valuable work.
Posted Image

williamsharkey
  • Members
  • 49 posts
  • Last active: Mar 14 2013 06:16 AM
  • Joined: 06 Oct 2007
With dynamic function calling, the possibilities are mind boggling. :shock: :shock: :shock:

TL
  • Members
  • 21 posts
  • Last active: Dec 16 2018 02:33 PM
  • Joined: 01 Nov 2006
I'm evaluating whether to switch to the new dynamic function method on my existing project. Some questions:

If I want to validate that a string contains a valid function name without executing the function at that time (for example, a function is registered in some way at program startup), is it best to still use the RegisterCallback function to see if an error occurs or is there a way that is quicker or doesn't depend on the number or type of parameters?

Also, if I use the Register Callback to validate the function's name should I then just use the old style DllCall method to invoke the function or is there an performance gain by using the new dynamic function method?

TL

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
You could use RegisterCallback to validate the function, then free the callback and use dynamic function calls. RegisterCallback fails for built-in functions or user-defined functions with ByRef parameters, while dynamic function calls support both.

Dynamic function calls require the function to be looked up every call. AutoHotkey searches the function list sequentially, so speed may vary depending on the order of functions: Explicitly included user-defined functions are first, followed by library and built-in functions (depending roughly on the order such functions are referenced in script.)

My benchmarks show dynamic function calls are roughly five times faster than DllCall when used with the first function in the script. I recommend benchmarking some scenarios typical to your script before deciding.

If your script would benefit from being able to pass strings to the callback rather than numbers or return values ByRef, dynamic function calls are the way to go.

or is there a way that is quicker or doesn't depend on the number or type of parameters?

I am nearly finished a function library for facilitating run-time code generation. It would typically be slower to generate the code to call a function, but once generated it would perform the same as a regular function call. LowLevel could potentially be used to validate the number and type of parameters.