Stopping compile time execution

rikki cattermole rikki at cattermole.co.nz
Fri May 25 16:00:26 UTC 2018


On 26/05/2018 3:58 AM, Russel Winder wrote:
> I have a bit of code which is the definition of a class Preferences,
> which has:
> 
> 	this() {
> 		filePath = expandTilde(chainPath("~", ".config", "me-tv", "preferences.yml").array);
> 
> filePath is a member of the class. Now if I have a module level
> instance (clearly not a good move but OK for now):
> 
>     public auto preferences = new Preferences;
> 
> then Dub using DMD on Debian Sid gives me:
> 
> /usr/include/dmd/phobos/std/path.d(3970,31): Error: getenv cannot be interpreted at compile time, because it has no available source code
> /usr/include/dmd/phobos/std/path.d(4064,41):        called from here: expandFromEnvironment(inputPath)
> source/preferences.d(36,25):        called from here: expandTilde(array(chainPath("~", ".config", "me-tv", "preferences.yml")))
> 
> What is the official way of getting preferences initialised at run time
> and not compile time.

Use a module constructor to initialize your global.



More information about the Digitalmars-d-learn mailing list