Re: Assocative array lookup for object
On Wednesday, 12 April 2023 at 01:16:17 UTC, Chris Katko wrote: Should I be using opEquals? Or something different? The problem with 'alias this' here is I want to wrap access to the insides with getter functions that do various things like logging and error checking. I think you want to do an encapsulation like below. ```d class Handler(T) { T*[string] data; auto set(string key, ref T value) => data[key] = auto opIndex(string key) => *(key in data); } void main() { class Bitmap {} Bitmap foo; auto handler = new Handler!Bitmap; handler.set("D Lang", foo); assert(handler["D Lang"] == ); } ``` SDB@79
Re: Assocative array lookup for object
You want the operator overload opIndex inside your class. https://dlang.org/spec/operatoroverloading.html#array
Assocative array lookup for object
```D class bitmapHandler { bitmap*[string] bmps; void get(string name){return bmps[name]; /* plus other code */} } void usage() { bitmapHandler bh; bitmap foo = bh.get("bar"); // works bitmap foo2 = bh["bar"]; // desired } ``` Should I be using opEquals? Or something different? The problem with 'alias this' here is I want to wrap access to the insides with getter functions that do various things like logging and error checking. I mean, if I ruined some encapsulation, I could make a function called "bh" and have the usage: ```D bh("bar"); ``` and have it access a singleton object.
Re: How to setup D with SFML? (using bindbc-sfml)
On Tuesday, 11 April 2023 at 11:55:50 UTC, Richard (Rikki) Andrew Cattermole wrote: I have to ask this since nothing else has worked and the dll's on the site don't depend on a MSVC dll: What are you compiling your program as? 32bit/64bit x86? ARM? Which DLL's are you downloading? 32bit, 64bit? I uses the default settings. DUB should compile my project as 64bit on Windows 10. The bindings I downloaded are also 64bit. The links mentioned in my previous post is what I use.
Re: mutable pointers as associative array keys
On Monday, 10 April 2023 at 20:31:43 UTC, Steven Schveighoffer wrote: On 4/10/23 4:25 PM, Steven Schveighoffer wrote: It's also completely useless. Having const keys does nothing to guarantee unchanging keys. Another half-assed attempt to be encode correct semantics but fails completely in its goal. In case you wonder how old this is: https://issues.dlang.org/show_bug.cgi?id=11477 https://issues.dlang.org/show_bug.cgi?id=12491#c2 -Steve Oh dear.
learning D as your first language but having difficulty in making or logic building in order to make software
I want to make software like krita inkscape and my own language using D Although i previosly learned C and C++ i left it in the middle and for some reasons i dont want to learn those so i searched for alternatives and found D but there are not a lot of resources like cookbooks and videos as compared to C or C++ does anybody know any resources for making complex software in D for some practise
SO_PRIORITY
`std.socket` is missing a `SocketOption`-equivalent to `SO_PRIORITY`. Is this an intentional omission (and if so, why?), or should I try to submit a PR to add it?
Re: How to setup D with SFML? (using bindbc-sfml)
I have to ask this since nothing else has worked and the dll's on the site don't depend on a MSVC dll: What are you compiling your program as? 32bit/64bit x86? ARM? Which DLL's are you downloading? 32bit, 64bit?
Re: How to setup D with SFML? (using bindbc-sfml)
On Sunday, 9 April 2023 at 14:20:30 UTC, Mike Parker wrote: 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. Well, `bin/` and `libs/` are in the same directory. 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/`. I tried `bin/libs/` as well as you describe here. It did not work. --- Actually, it is quite strange that it fails to load the [CSFML](https://www.sfml-dev.org/download/csfml/) library dlls in `libs/` (I download CSFML2.5) since that is what I do with [GLFW/OpenGL](https://github.com/rillki/d-glfw-opengl-project-template) example as well for Windows 10. **Even this fails: `loadSFMLGraphics("libs/csfml-graphics.dll")`** I have the following structure: ``` - bin/ - libs/ - source/ - dub.json - dub.selections.json ``` My `dub.json`: ```Json { "authors": [ "rillki" ], "copyright": "Copyright © 2023, rillki", "dependencies": { "bindbc-sfml": "~>1.0.2" }, "description": "D/SFML project template", "license": "BSL", "name": "d-sfml-project-template", "targetPath": "bin", "versions": [ "SFML_Audio", "SFML_Graphics", "SFML_Network", "SFML_System", "SFML_Window", "SFML_250" ] } ``` My `source/app.d`: ```d module app; import std.stdio: writeln; import bindbc.sfml; void main() { version(Windows) { import bindbc.loader; setCustomLoaderSearchPath("libs"); } // attempt at loading sfml if(!loadSFML()) { writeln("Failed to load SFML library!"); return; } // window dimensions enum width = 720; enum height = 480; enum title = "D/SFML project"; // create window auto window = sfWindow_create(sfVideoMode(width, height), title.toStringz, sfWindowStyle.sfDefaultStyle, null); scope(exit) { sfWindow_destroy(window); } while(sfWindow_isOpen(window)) { // process events sfEvent event; while(sfWindow_pollEvent(window, )) { if(event.type == sfEventType.sfEvtClosed) { sfWindow_close(window); } } // ... } } ``` I will try to make it work... Meanwhile, if someones spots what I am doing wrong, please reply to this post.