www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What is "stringImportPaths"

reply mrphobby <mrp spinrock.net> writes:
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?
Dec 06 2017
next sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/06/2017 11:05 AM, mrphobby wrote:

 importing is a construct used for importing symbols, right?
That's the import statement. -J compiler switch is about the import expression: https://dlang.org/spec/expression.html#import_expressions Ali
Dec 06 2017
parent Atila Neves <atila.neves gmail.com> writes:
On Wednesday, 6 December 2017 at 20:17:55 UTC, Ali Çehreli wrote:
 On 12/06/2017 11:05 AM, mrphobby wrote:

 importing is a construct used for importing symbols, right?
That's the import statement. -J compiler switch is about the import expression: https://dlang.org/spec/expression.html#import_expressions Ali
I went looking for that and didn't find it! I searched for "string imports" but apparently that doesn't quite work.
Dec 06 2017
prev sibling next sibling parent Atila Neves <atila.neves gmail.com> writes:
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
Dec 06 2017
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2017-12-06 20:05, 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?
There are two kinds of language constructs that uses the "import" keyword. One is the "Import Declaration" [1] which is the most common one and is used to import other symbols. The other language construct is the "Import Expression" [2], which is used to read a file at compile time and put its content into a string literal in your source code. Anything specified to the "stringImportPaths" build setting will be sent to the compiler with the -J flag. [1] https://dlang.org/spec/module.html#ImportDeclaration [2] https://dlang.org/spec/expression.html#import_expressions -- /Jacob Carlborg
Dec 07 2017
parent reply mrphobby <mrp spinrock.net> writes:
On Thursday, 7 December 2017 at 09:47:31 UTC, Jacob Carlborg 
wrote:
 On 2017-12-06 20:05, mrphobby wrote:
 There are two kinds of language constructs that uses the 
 "import" keyword. One is the "Import Declaration" [1] which is 
 the most common one and is used to import other symbols. The 
 other language construct is the "Import Expression" [2], which 
 is used to read a file at compile time and put its content into 
 a string literal in your source code.

 Anything specified to the "stringImportPaths" build setting 
 will be sent to the compiler with the -J flag.

 [1] https://dlang.org/spec/module.html#ImportDeclaration
 [2] https://dlang.org/spec/expression.html#import_expressions
Ok thanks! I couldn't find that in the docs so kudos for pointing me to it. I still think using the word "import" is confusing. Would rather have it called "load" or something. But at least I understand it now :)
Dec 08 2017
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/08/2017 12:10 PM, mrphobby wrote:

 I still think using the word "import" is confusing. Would rather have it
 called "load" or something. But at least I understand it now :)
We don't want any more keywords. :) (D's keywords are context-independent.) An unfortunate example was the "body", which is on its way out of being a keyword. Instead, the "do" keyword is overloaded to take "body"s responsibility: int foo(int i) in { assert(i < 100); } out(result) { assert(result > i); } do { auto body = i + 7; // YAY! :) return body; } void main() { foo(42); } Of course the same can be said about any other keyword but life is not fair. :) Ali
Dec 08 2017