On Friday, 27 December 2013 at 07:31:19 UTC, nazriel wrote:
On Friday, 27 December 2013 at 06:39:54 UTC, Ravn wrote:
Hi, I'm trying get the directory path and time at which the
compilation was made (not when the program is run), something
similar like this example in Haxe
http://haxe.org/manual/macros#macro-functions

Is it possible to do so in D?
Something like __DIR__ and __DATE__ or __TIME__ in D traits maybe?
( http://dlang.org/traits.html#specialkeywords )

Thanks in advance
-Ravn-

Hello.

Maybe this will work for you?
http://dpaste.dzfl.pl/3ad4aa3a

---
void main()
{
        import std.path: dirName;
        
pragma(msg, dirName(__FILE__) ~ " " ~ __DATE__ ~ " " ~ __TIME__);
}
---

Hi, thanks for the answer,
I've tried your solution, but I need to store the path and time to be used for various stuffs later, not just during errors, maybe something closer to this,

Example:
    file located at D:\misc\hello.d

if there's a code like this

    // inside hello.d
    void main()
    {
        string path = getAbsolutePath();
        string date_and_time = getDateAndTime();
    }

I would like the compiler to specifically process the return value of getAbsolutePath() as well as getDateAndTime during compile time.

So that whenever I run the program, its as if the code above is written and compiled as the following code,

    // inside hello.d
    void main()
    {
        string path = "D:\misc\";
        string date_and_time = "Dec 2x 20xx hh:mm:ss";
    }

Would that be possible?
-Ravn-

Reply via email to