More Flexibility with #Requires Topic is solved

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

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: 9583
Joined: 30 Sep 2013, 04:07
Contact:

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: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

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: 1640
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: 9583
Joined: 30 Sep 2013, 04:07
Contact:

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.
User avatar
RaptorX
Posts: 378
Joined: 06 Dec 2014, 14:27
Contact:

Require bitness for script

13 Nov 2022, 10:09

I love the #Requires directive.

I was wondering if it is feasible to add the bitness to the requirement. something like: #Requires Autohotkey v2.0- 32bit.

Some times I write scripts that depend on dll files that are 32bit and when trying to run the script with 64bit (default ahk installation) would fail.

I usually handle that inside the script by using error checking (library could not be loaded) or sometimes just forcing the script to load with a specific version of ahk automatically by means of:

Code: Select all

#Requires Autohotkey v1.1.33+

if ((A_PtrSize = 8 || !a_isunicode) && !a_iscompiled)
{
	SplitPath, A_AhkPath,, ahkDir
	ahkpath := ahkDir "\AutoHotkeyU32.exe"

	if (!FileExist(ahkpath) && !ahkpath := a_ahkpath){
		ahkpath := a_temp "\ahkl.bak"
		FileInstall, res\ahkl.bak, %ahkpath%, true
	}

	Run %ahkpath% "%A_ScriptFullPath%"
	ExitApp
}
But this code must check that ahk actually exists before forcing the reload.

Having a quick requirement at the top of the script indicating not only the version but also the bit requirement might make things a bit clearer.
Projects:
AHK-ToolKit
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: More Flexibility with #Requires

13 Nov 2022, 19:19

I have decided to extend the directive to allow specifying the required bitness and (for v1 only) Unicode/ANSI, and further extend the launcher to allow specifying these things as preferences rather than requirements.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: More Flexibility with #Requires

13 Nov 2022, 19:24

@RaptorX I moved your post into this topic.
User avatar
RaptorX
Posts: 378
Joined: 06 Dec 2014, 14:27
Contact:

Re: More Flexibility with #Requires

16 Nov 2022, 14:21

lexikos wrote:
13 Nov 2022, 19:19
I have decided to extend the directive to allow specifying the required bitness and (for v1 only) Unicode/ANSI, and further extend the launcher to allow specifying these things as preferences rather than requirements.
Thats perfect!

It would help clean up some old code and also would remove inconsistencies as some situations might make it difficult to really determine AHK's path or even remove the need to install a backup AHK file in certain situations too.
Projects:
AHK-ToolKit
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: More Flexibility with #Requires  Topic is solved

02 Dec 2022, 06:08

v1.1.36 implemented the following keywords: Unicode, ANSI, 32-bit, 64-bit

The next v2 release will implement 32-bit and 64-bit.

The suggestion about file existence will not be implemented.
User avatar
RaptorX
Posts: 378
Joined: 06 Dec 2014, 14:27
Contact:

Re: More Flexibility with #Requires

02 Dec 2022, 09:52

lexikos wrote:
02 Dec 2022, 06:08
v1.1.36 implemented the following keywords: Unicode, ANSI, 32-bit, 64-bit

The next v2 release will implement 32-bit and 64-bit.

The suggestion about file existence will not be implemented.
Excellent news!

I was not really suggesting adding whether the file existed or not to the #requires directive.
I was just describing what i had to do which the #requires directive was going to help me with!

Now I dont need to add that block of code! :)
Thanks for the update!
Projects:
AHK-ToolKit
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: More Flexibility with #Requires

10 Feb 2023, 00:11

I found a neat trick to update the version number for all my scripts:
  1. In File Explorer, go to the folder with all my scripts.
  2. In the search box, type *.* (This will show all scripts in the folder and subfolders.).
  3. Press Ctrl + A, Shift + F10 (or right-click a script), and then open with Notepad++ (Which can replace in all documents).
  4. In Notepad++, press Ctrl + H to open Replace.
  5. Filled that text fields and click Replace All in All Opened Documents
I can then close all that tabs by:
  1. Right clicking a tab.
  2. Selecting "Close Multiple Tabs", And then "Close All BUT This".
  3. Press Ctrl + W.
:D

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 50 guests