Hi everybody,
I think that ready access to a program's environment variables and command line parameters is not a high-level language privilege but rather a must.
Even (comparatively) low-level C provides the programmer with those through the
argv[] (param array),
argc (param count) arguments to the C program's conventional main entry point defined by the program's
main() function. Actually, this isn't the first function that the program would execute at its start time. The C linker would pre-link a lot more functions into the program binary preceding the point at which main() is executed, one of which would always be supposed to provide the main() function with the
argv[] command line parameter array and its associated
argc count. The exact list and tasks of those extra prologue functions would be compiler and platform dependent but in any case, the programmer would be provided with equal functionality of main() transparently regardless of what compiler they use and on what platform they currently are.
It is only in GUI programs that the C programmer is supposed to call GetCommandLine() under Windows themselves and parse its return string manually but I really do not see any reason why a higher-level language such as OxygenBasic shouldn't ensure that its users can access the command line parameters through a convenient function of the language itself.
FBSL provides the programmer with a
STANDALONE environment constant that's TRUE if the program runs precompiled from a stand-alone binary, and FALSE otherwise if interpreted or JIT compiled depending on its content. Access to command line arguments is ensured in both console and GUI scripts via uniform
Command() and
CommandCount() functions, whereby:
- Command(0) always returns the name of the binary that's currently running: fbsl.exe/fbsl_tiny.exe if STANDALONE = FALSE or the actual name of the binary otherwise;
- Command(1 ... n) returns a pre-split CommandCount()-dependent string value of the respective parameter or empty strings if n exceeds the actual command count;
- a special Command(-1) call returns the entire command line exactly as a GetCommandLine() call would.
[EDIT] Additionally, FBSL provides an
APPEXEPATH environment constant that always returns a fully qualified path to the binary that is currently running. This would evaluate to the location where Fbsl.exe and/or Fbsl_Tiny.exe is/are installed if the program runs in the interpretative/JIT compiled mode and the respective STANDALONE value is FALSE, or to the fully qualified path to the precompiled program executable if it is running from its own binary and the respective STANDALONE value is TRUE.
Once an FBSL standalone program is started, its current directory path is always changed to where its binary is located, and the programmer can always resolve any extra relative path dependencies using a
CurDir() function call and point the program's current path focus to other disk locations using a
CD pathname (= chdir, change current directory) command.