[v1.1 & v2] Add OS version requirement options to #Requires directive

Propose new features and changes
User avatar
Animan8000
Posts: 58
Joined: 11 May 2022, 05:00
Contact:

[v1.1 & v2] Add OS version requirement options to #Requires directive

16 Feb 2023, 07:41

While yes, you can write this yourself in a few lines of code, the idea is to make the directive even more flexible. This is useful in cases where the user may unfortunately use a really old OS version where the script wouldn't work properly anyway (because of differences in the WinAPI).
geek
Posts: 1053
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: [v1.1 & v2] Add OS version requirement options to #Requires directive

16 Feb 2023, 13:11

The #Requires directive supplies AHK with information about the environment required to make sense of the script, for two reasons.

First, it allows scripts with different syntax to generate a meaningful error when a too-old or wrong branch interpreter version is used (e.g. an AHK_H script trying to be run by standard AHK), instead of having unexpected behavior or a random syntax error.

Second, it allows the launcher to choose the right interpreter to use to make sense of the script. This is where the options to choose Unicode/ANSI/32-Bit/64-Bit come in.

In both of those cases, having the requirement as a #Requires is strictly necessary for the desired effect. You can't enforce an interpreter version minimum at run-time when load-time differences can cause syntax parsing errors, and although you could enforce Unicode/ANSI/32-Bit/64-Bit at run-time, it would be by giving an error that you used the wrong version rather than just automatically using the right version.

Whereas with OS version requirement, you absolutely can do it at run-time. Any OS difference that would prevent the script from loading should be detected by the interpreter itself regardless of your script contents, as per the interpreter's own minimum supported version requirements. Once your script loads, especially in v2, you can check the OS version easily by A_OSVersion before ever touching the windows API (in any meaningful way). There is no additional feature (like automatic interpreter choosing) that this metadata would enable, as it can't automatically choose to run with a different version of the windows API (except maybe forcing a simulated older version by applying compatibility mode flags, but I think that's a bit beyond the scope of what #Requires should try to achieve).

It makes the directive more complicated, but not in a way that expands AHK's total feature set.



Tangential note: Checking against the OS version is much less powerful than checking for the availability of the specific features you want to utilize, and that's something that #Requires will never be able to do. Checking the specific availability improves compatibility with windows-ish platforms like Wine and Valve's Proton, and ensures that if the feature is removed in future windows API versions that the script will still produce a meaningful error.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 15 guests