www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13347] New: rdmd: let args[0] be the .d file


          Issue ID: 13347
           Summary: rdmd: let args[0] be the .d file
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: tools
          Assignee: nobody puremagic.com
          Reporter: nilsbossung googlemail.com

When rdmd is used to sort-of interpret a .d file, it's actually compiled to a
temporary executable and then run. As usual, args[0] is then the temporary
executable. That path is next to useless, though.

Other interpreters (bash, python, perl, php) pass the script file as args[0].
This allows to write scripts that act relative to the script file, no matter
from where they were run.

Would be nice if rdmd did that, too. This would be a breaking change, of
course. But I can't imagine someone making use of the path to the temporary.

cat > test.d << code
import std.stdio;
void main(string[] args) {writeln(args[0]);}
rdmd test.d

Compare with bash, python, perl, php:

echo 'echo $0' > test.sh
bash test.sh
echo 'print "$0\n"' > test.pl
perl test.pl
echo 'import sys; print sys.argv[0]' > test.py
python test.py
echo '<?php echo "{$argv[0]}\n";' > test.php
php test.php

Aug 20 2014