How do I access the program name / argv[0] in Forth?

367 Views Asked by At

The Gforth documentation say to access arguments by calling next-arg, but this omits the program name, which would be printed in a C-like language.

Since argv[0] seems to be automatically removed from the argument vector in Forth, is there a special function I can call that does return it?

2

There are 2 best solutions below

2
On BEST ANSWER

sourcefilename gives the program's name, and n arg gets the arguments that were sent to gforth, including the gforth binary name.

0
On

0 arg will always return argv[0], while the rest of the arg list is modified by next-arg. sourcefilename is the name of the file you are just loading.