What is "stringImportPaths"
Atila Neves
atila.neves at gmail.com
Wed Dec 6 20:20:33 UTC 2017
On Wednesday, 6 December 2017 at 19:05:24 UTC, mrphobby wrote:
> Can anyone explain what "stringImportPaths" is? I have seen
> this being used in dub.json files and I think I kind of know
> what it does, but I haven't been able to find a clear
> explanation in any documentation of what it does. It does not
> look like anything I'm familiar with from other languages.
>
> I understand it can be used for resources but I have seen it
> being used with both text files and binary files so I'm a bit
> confused. The documentation says I can import "whatever", but
> that feels a bit weird since importing is a construct used for
> importing symbols, right?
stringImportPaths are to -J what importPaths are to -I. In D you
can import a string directly into your program, similarly to
#include in C and C++. Imagine it as kind of a
mixin(read("filename")) (which you can't do). For security
concerns, dmd only looks for "filename" in directories passed in
with -J.
A silly example:
foo.d:
import std.stdio;
void main() {
mixin(`auto values = [` ~ import("foo.txt") ~ `];`);
writeln(values);
}
foo.txt:
1, 2, 3, 4, 5
$ dmd -J. foo.d
$ ./foo
[1, 2, 3, 4, 5]
Atila
More information about the Digitalmars-d-learn
mailing list