How do I do this?

Shachar Shemesh via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 3 04:00:36 PDT 2017


No sooner did I send out this question I have found the D feature I've 
been looking for. This is what I have:

module log;

version(alternate_logger) {
mixin("public import " ~ import("alternate_logger.txt") ~ ";");
} else {

// Default implementation goes here

}

Can't say I'm thrilled with this, but it does get the job done. 
Suggestions more than welcome.

Shachar

On 03/08/17 13:46, Shachar Shemesh wrote:
> The problem: I'm writing a library. This library has logging facilities, 
> but where it's going to be used there are better logging facilities. 
> Under C, that wouldn't be a big issue:
> 
> log.h:
> #ifdef REAL_LOG_LIBRARY
> #include REAL_LOG_LIBRARY
> #else
> 
> // Declarations go here
> 
> #endif
> 
> 
> I can now inject from my build system -DREAL_LOG_LIBRARY=real/impl/log.h 
> into the compilation command line, and I'm done.
> 
> Under D, there is no facility to transfer a string from the command line 
> to the code, so I can't use that approach.
> 
> I seem to remember that D had an option of importing an external file as 
> something (string? code? anything would do for my purposes). I cannot 
> seem to find it, however. A search for "string import" and "import 
> mixin" brought back nothing useful.
> 
> Help?
> Shachar



More information about the Digitalmars-d mailing list