compile time configurations

Freddy via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 8 15:34:36 PDT 2014


I recently thought of the idea of using string imports for
compile time configuration.
Something like this
---
import std.stdio;
import std.conv;
import std.range;
import std.algorithm;

string getVar(string fname,string var)(){
	foreach(property;import(fname).splitter('\n')){
		auto varname=property[0..property.countUntil("=")];
		if(var==varname){
			return property[property.countUntil("=")+1..$];
		}
	}
	assert(0, "unable to find property");
}

enum dimisions=getVar!("shapes","dimisions").to!uint;

void main()
{
	writeln("There are ",dimisions," dimisions");
}
---
Where you add your config dir(that contains "shapes") file to
dub's  stringImportPaths".
How do you guys feel about this? Should we use something like
json for config files?


More information about the Digitalmars-d mailing list