Expand/Shrink

requires

Definition: requires(object x, bool bQuiet=false)
Description: Specifies the requirements needed for a particular source code file to be executed.
pwa/p2js: Supported. Obviously unlike desktop/phix there is no attempt to restart the browser in 64 bit mode. Valid settings for x to run in a browser are a suitable version string, or JS (aka 4), 6 (aka WIN/JS), 7 (aka WIN/LNX/JS), 8 (aka LNX/JS), or 32. Note that JavaScript is inherently a 32 bit system (cmiiw, afaik even 64-bit browsers all contain a 32-bit JS runtime), so requires(64) in a browser will always trigger a crash message.
Comments: If x is a string, eg "0.8.2", it compares it (intelligently) against version() and displays a message and terminates execution when necessary.

If x is an integer between 0 and 31, it compares it against platform() and displays a message and terminates execution when necessary. See technicalia for combinations.

Otherwise x should be 32 or 64, which is compared against machine_bits() and when necessary it uses bQuiet and get_interpreter(true,{x},platform(),bPrefW) to construct a suitable replacement commandline, which it then either offers to execute when bQuiet is false (or 2), or executes automatically when bQuiet is trur (or 3), see examples and details below. In short, eg requires(64) is "let them know" whereas requires(64,true) is your "just do it", see technicalia for the minutae.

If no suitable interpreter can be found it displays an appropriate message instead.

You can also invoke requires(-machine_bits()) to trigger a similar "requires restart" prompt.
Example:
requires("0.8.2")                           -- crashes on 0.8.1 and earlier
requires(WINDOWS)                           -- crashes on Linux
printf(1,"running %d-bit\n",machine_bits())
requires(96-machine_bits()) -- (toggle 32<==>64 [a rather daft thing to do!])

-- example output (forever in this rather silly little case):
--running 32-bit
--requires 64 bit: "C:\Program Files\Phix\p.exe" "C:\Program Files (x86)\Phix\test.exw"
--Press Escape to abandon, Enter to retry as above...
--running 64-bit
--requires 32 bit: "C:\Program Files (x86)\Phix\p.exe" "C:\Program Files (x86)\Phix\test.exw"
--Press Escape to abandon, Enter to retry as above...

Of course the more sensible requires(32) or requires(64) would only display 0 or 1 such steps.
While the prompt may be mildly annoying, and no-one in their right mind would ever code the above, it is reasonably likely a main app might start off with requires(64) but then include a component that says requires(32), or vice versa, and without the pause it would spawn alternately/madly and in all probability completely lock up the machine. For focus reasons (specifically Edita/Edix) a requires() call does not terminate until after the freshly-spawned subprocess has terminated.
Implementation: See builtins\get_interpreter.e (an autoinclude) for details of the actual implementation, there is also a hand-translated and simplified version in p2js.js
See Also: command_line, get_interpreter, machine_bits, platform, version
Expand/Shrink