digitalmars.D.learn - How to embed static strings to a D program?
- Ky-Anh Huynh (8/8) Oct 15 2017 Hello,
- evilrat (11/19) Oct 15 2017 import can do this, basically it gives you an array that you can
- Adam D. Ruppe (3/6) Oct 16 2017 Arrays yes, but not strings. So you can do `enum data =
Hello, I want to use some static contents in my program, e.g, a CSS file, a long listing. To help deployment process I'd like to have them embedded in the final binary file. Is there any convenient way to support this? Maybe I need a tool/library to load file contents and generate D-code at run-time ? Thanks for your reading.
Oct 15 2017
On Monday, 16 October 2017 at 05:34:13 UTC, Ky-Anh Huynh wrote:Hello, I want to use some static contents in my program, e.g, a CSS file, a long listing. To help deployment process I'd like to have them embedded in the final binary file. Is there any convenient way to support this? Maybe I need a tool/library to load file contents and generate D-code at run-time ? Thanks for your reading.import can do this, basically it gives you an array that you can cast to ubyte[] for binary too, be careful with enums though, because enum arrays will allocate every time you access it string data = import("strings.txt"); more https://dlang.org/spec/expression.html#import_expressions However for security reasons it only looks in folders which you pass with -J flag or with dub using "stringImportPaths" http://code.dlang.org/package-format?lang=json
Oct 15 2017
On Monday, 16 October 2017 at 06:03:40 UTC, evilrat wrote:can cast to ubyte[] for binary too, be careful with enums though, because enum arrays will allocate every time you access itArrays yes, but not strings. So you can do `enum data = import("strings.txt");`.
Oct 16 2017