Thread overview | |||||
---|---|---|---|---|---|
|
May 25, 2018 Stopping compile time execution | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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. -- Russel. =========================================== Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk |
May 26, 2018 Re: Stopping compile time execution | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | 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.
|
May 25, 2018 Re: Stopping compile time execution | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole Attachments:
| On Sat, 2018-05-26 at 04:00 +1200, rikki cattermole via Digitalmars-d- learn wrote: > […] > > Use a module constructor to initialize your global. Splendid idea! :-) I know, I should have thought of that. I note that if you click "Constructor" on https://dlang.org/spec/module .html you get taken to https://dlang.org/spec/class.html#Constructor which really does help describe the concept of a module constructor. -- Russel. =========================================== Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk |
Copyright © 1999-2021 by the D Language Foundation