Skip to content

Instantly share code, notes, and snippets.

@bithavoc
Created March 25, 2014 05:01
Show Gist options
  • Save bithavoc/9755523 to your computer and use it in GitHub Desktop.
Save bithavoc/9755523 to your computer and use it in GitHub Desktop.
Compile-Time file import in D
import std.stdio;
template loadFile(string filePath, string accessorName) {
const char[] loadFile = "@property string " ~ accessorName ~ "() { return \"" ~ import(filePath) ~ "\";}";
}
mixin(loadFile!("hello.txt", "contentOfHelloDotTxt"));
void main()
{
writeln(contentOfHelloDotTxt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment