getting __DIR__ and __TIME__ of compilation?
Lemonfiend
lemon at fie.nd
Fri Dec 27 03:51:04 PST 2013
On Friday, 27 December 2013 at 08:57:02 UTC, Ravn wrote:
> 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-
module main;
import std.stdio;
enum file = __FILE__;
enum time = __TIME__;
void main()
{
writeln(file);
writeln(time);
}
This works for me.
More information about the Digitalmars-d-learn
mailing list