Re: How come a count of a range becomes 0 before a foreach?
On 4/9/23 9:16 AM, Ali Çehreli wrote: On 4/8/23 21:38, ikelaiah wrote: > I will modify the code to construct it twice. Multiple iterations of dirEntries can produce different results, which may or may not be what your program will be happy with. Sticking an .array at the end will iterate a single time and maintain the list forever because .array returns an array. :) auto entries = dirEntries(/* ... */).array; I'd be cautious of that. I don't know what the underlying code uses, it may reuse buffers for e.g. filenames to avoid allocation. If you are confident the directory contents won't change in that split-second, then I think iterating twice is fine. -Steve
DYaml
Hi All, I am trying to use D-YAML for one of my project, and just tired the example for this link https://dlang-community.github.io/D-YAML/tutorials/getting_started.html, the example is working fine, so i would like to know who to i validate the node, eg Example Code ``` import std.stdio; import std.algorithm; import dyaml; alias isReserverd = among!("name", "type"); int main(string[] args) { string path = "input.yml"; try { auto loader = Loader.fromFile(path); auto root = loader.load(); if(root[*].isReserverd) // This is condition { writeln(root[*]); return 0; } } catch(YAMLException e) { writeln(e.msg); } writeln("FAILURE"); return 1; } ``` input.yml ``` name: Test type: A records: 10 ``` Required output ``` Test A ``` From, Vino.B
Re: How to setup D with SFML? (using bindbc-sfml)
On Sunday, 9 April 2023 at 09:54:26 UTC, Ki Rill wrote: Why can't it find these libraries? I tell where to look for them: ```D version(Windows) { import bindbc.loader; setCustomLoaderSearchPath("libs"); // tried using absolute path as well } ``` That is strange... I've tried your project out two ways, one that succeeds and one that fails. I'm guessing you've put your 'libs' directory is 'bin/libs'. Am I right? If so, then the following should help you. When dub runs the exectuable, it sets the current working directory to the project's root directory by default. `setCustomLoaderPath` passes whatever you give it directly to the system API unmodified. You've passed a relative path. By default, the system API associates relative paths with the current working directory. So given a project root directory of `$ROOT`, and your executable in `$ROOT/bin`, the system is looking for the libraries in `$ROOT/libs` and *not* in `$ROOT/bin/libs`. If the libs are in the former, everything loads. If they're in the latter, then it's going to fail. If you cd into `bin` and run the executable manually, then libs in `$ROOT/bin/libs` will load, as your current working directory is `bin`. The quick fix for this is to add `"workingDirectory" : "bin"` to your dub.json. Then your relative paths will be relative to `$ROOT/bin/`. Bear in mind that when using relative paths like this, any file reading is bound to break if someone runs your executable from outside its directory. You can test this by going into `$ROOT` from the command line and executing `bin/d-sfml-project-template`. Then you'll be doing the same thing dub does, i.e., your working directory will be `$ROOT`. The way to guarantee your relative paths are always relative to the executable are to either set the current working directory to the executable's path, or to prepend all relative paths with the executable's path before handing them off to the system. There are two ways you can get the full path to the executable in Phobos/DRuntime: via `std.file.thisExePath`, or `core.runtime.Runtime.args[0]`. (The former is failing to compile for me on Windows right now due to a bug in the Phobos Win32 API bindings. I'll look into it.) Strip the file name from the returned path, then you can use it as required.
Re: How come a count of a range becomes 0 before a foreach?
On 4/8/23 21:38, ikelaiah wrote: > I will modify the code to construct it twice. Multiple iterations of dirEntries can produce different results, which may or may not be what your program will be happy with. Sticking an .array at the end will iterate a single time and maintain the list forever because .array returns an array. :) auto entries = dirEntries(/* ... */).array; Ali
Re: How to setup D with SFML? (using bindbc-sfml)
On Saturday, 8 April 2023 at 23:40:32 UTC, Mike Parker wrote: On Saturday, 8 April 2023 at 11:31:40 UTC, Ki Rill wrote: How do I set up a D and SFML project using the `bindbc-sfml` package? I tried following the instructions, it builds successfully, but fails to load the SFML library at runtime. In particular, `loadSFML, loadSFMLGraphics, loadSFMLXXX` fails. Here is [link](https://github.com/rillki/d-sfml-project-template) to the repo. I plan to create another how-to video, but I cannot find what's causing it to fail. Do you have any ideas? Not without error messages. The first thing you should do is use the error API in bindbc.loader to print them out. That should tell you what the problem is. I forgot about that). Here are the errors that occur on Windows: ``` csfml-system.dll, The specified module could not be found. csfml-audio.dll, The specified module could not be found. csfml-audio-2.dll, The specified module could not be found. csfml-audio-2.0.dll, The specified module could not be found. ``` Why can't it find these libraries? I tell where to look for them: ```D version(Windows) { import bindbc.loader; setCustomLoaderSearchPath("libs"); // tried using absolute path as well } ``` That is strange...