injecting imports when compiling
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Dec 7 14:56:56 UTC 2021
On Tue, Dec 07, 2021 at 02:35:15PM +0000, Rumbu via Digitalmars-d wrote:
[...]
> On the other hand, placing a simple ```import std``` at the beginning
> of your module will have the same effect.
Better yet, create a file called something like common.d containing
public imports of everything you want to share across files, and just
import it at the top of each file:
// common.d
module common;
public import std;
public import whatever.else.you.want;
...
// in each file:
import common;
Or, if you want to be able to switch out the common import dynamically,
you could use this trick I recently invented: add this to the top of
every file:
import __stdin;
then run your compile command with:
echo 'public import std; public import whatever.else;' | dmd - mysources.d ...
Then you can inject arbitrary D code into your project via the command
line.
T
--
People say I'm indecisive, but I'm not sure about that. -- YHL, CONLANG
More information about the Digitalmars-d
mailing list