More Flexibility with #Requires

Propose new features and changes
User avatar
Delta Pythagorean
Posts: 567
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

More Flexibility with #Requires

17 Jul 2020, 07:50

As of AHK 1.1.33, the #Requires directive was added, allowing users to require others for a certain version (or higher) of AHK to be ran with the script. I see very little use with this directive with it only being used to check for the ran version of AHK. My "wish" is to allow more options for the "Requirement" parameter. I have a few ideas:
  • Unicode VS ANSI. Allowing the user to download or save a script to their computer to try out or mess around with is quite nice, but sometimes using Unicode vs ANSI is required in some cases.
  • 32 VS 64 bit. Displaying a message is sometimes not enough, and the whole purpose of the #Requires directive is to require a certain condition to be met. Allowing the script to be ran in a certain bit size rather than have an If line at the beginning of the script would help a bit.
  • File Existance. Downloading a single file of a script and not the necessary Dynamic Link Libraries for the script to work could cause problems along the way, and as I've said above, putting an If at the beginning of a script isn't too helpful.
If there are any others, or any feedback about this, I'd love to hear it.
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: More Flexibility with #Requires

18 Jul 2020, 22:20

I added #Requires primarily for v1 vs. v2 (and future versions with incompatible syntax), where one often cannot load a script intended for the other. It's main purpose is to encourage a standard way to identify the version of a script, so that the installer can eventually support both versions, and allow launching of either via double-click on an .ahk file. Emphasis (and my priority) is on v2, which is always Unicode.

There is nothing stopping you from checking A_IsUnicode, A_PtrSize, FileExist() or any other arbitrary requriements in your script. By contrast, a script that contains v1-specific or v2-specific syntax typically cannot do this check, because it cannot even start.

As always, if someone else wants to develop this, I would consider a pull request according to whatever merits and cost I perceive. However, I have no intention of extending #Requires in this manner myself.

Displaying a message is sometimes not enough
But that's all #Requires does when the requirement isn't met, and that's likely all it will ever do. The purpose of the directive is to prevent the program from attempting to load or execute script when the requirement isn't met. If you want the program to do something other than show a message, your script must be able to run. The alternative is to use an external solution (such as a launcher, compiling the script, including the relevant AutoHotkey.exe, or some other way to prevent users from attempting to run the script with the wrong version).
Allowing the script to be ran in a certain bit size rather than have an If line at the beginning of the script would help a bit.
How so?

If the script is capable of being parsed and executed by AutoHotkey.exe, the directive is nothing more than an IF checking the requirement condition followed by a call to MsgBox. Adding this to the directive would only save a small amount of typing, and perhaps make it more likely that code snippets posted on the forum would have their requirements enforced. However, it's better to write code that works in the first place. ;) I think it's generally rare that a script couldn't be written to support both 32-bit and 64-bit; the only example that comes to mind is the use of 32-bit components such as ScriptControl, but that has alternatives which work with 64-bit.
... as I've said above, putting an If at the beginning of a script isn't too helpful.
That seems to have a somewhat different meaning to what you actually said, and I think is more exaggerated. How is it not helpful to check the conditions with your own code? It's less obvious to anyone looking than the words "requires file x.y", but obviously you can comment your code as well.
User avatar
Delta Pythagorean
Posts: 567
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: More Flexibility with #Requires

19 Jul 2020, 18:53

I do agree on the points you made, and I want to kind of clarify that some of my ideas were more or less just rambling about a new feature and having ideas just spitting out of my mouth. As a side note I generally try to come up with ideas and see what others think about them.
Yes, I do see the flaws with some of my ideas. But I will say this though, I see #Requires to be somewhat useless, mostly for the reason that it was added pretty far into development of both AHK v1 and v2, but it does give better control on sharing scripts and hinting to users that a certain version of AHK is required to use it like the directive is supposed to do.
Sorry if I seemed to just throw whatever came to my mind without thinking twice. Again, I try to come up with ideas, and I guess most of my ideas aren't the greatest. :crazy:
Thanks for the feedback though!
User avatar
kczx3
Posts: 1163
Joined: 06 Oct 2015, 21:39

Re: More Flexibility with #Requires

19 Jul 2020, 21:07

@lexikos
Silly question but why do you require the directive requirement to contain the word AutoHotkey?
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: More Flexibility with #Requires

20 Jul 2020, 04:57

Delta Pythagorean wrote:I see #Requires to be somewhat useless, mostly for the reason that it was added pretty far into development of both AHK v1 and v2
That's more or less why it wasn't added earlier - at any point that it could be added, it would always be useless for specifying the requirements of scripts written for past versions, or dealing with scripts that never used it. It doesn't have to be useful now - it just has to be added some time, so that it will be useful in future.

But it is useful now, if scripts use it, for the purposes I documented and mentioned. And it will be more useful when simultaneous installation of multiple incompatible versions is officially supported.

@kczx3
  1. For clarity to someone reading the script.
  2. So that a launcher script can detect the words "requires AutoHotkey v" or just "AutoHotkey v", which may be present in a comment or the directive.
  3. So that @HotKeyIt (or any other branch developer) can modify it to support his own branch name, such as #Requires AutoHotkey_H.
  4. To allow for potential future expansion, such as for required module/library versions.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 2 guests