Re: D static library on Windows 64 problem
On Sunday, 3 January 2021 at 15:49:03 UTC, Imperatorn wrote: On Saturday, 2 January 2021 at 22:08:34 UTC, WhatMeWorry wrote: On Saturday, 2 January 2021 at 22:04:28 UTC, WhatMeWorry wrote: I'm stepping through the windows static library tutorial at http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial/CompilingLinkingD#Linkingmanually [...] Oops. used the manual example. Should be /LIBPATH:c:\dev\LibraryStudy\StaticLibrary\libfoobar If it doesn't say so on the wiki (haven't read), could you update it with your findings? Thanks! I'm sorry. The correction was for my first post, not the tutorial. If the tutorial was written for 64 bits I wouldn't be having this problem :)
Re: D string to C struct fixed-size array
On Sunday, 3 January 2021 at 11:16:25 UTC, rikki cattermole wrote: Your definition of Image is probably wrong. You may have missed a pointer (8 bytes). I'm pretty sure it's correct? Here's the D version: https://repo.or.cz/magickd.git/blob/e5d06e939:/source/magickd/core/c/image.d#l751 Here's the C version: http://hg.code.sf.net/p/graphicsmagick/code/file/a622095da492/magick/image.h#l683
Re: Simple BeamUI project won't link
On Saturday, 2 January 2021 at 15:48:11 UTC, Kyle Ingraham wrote: On Friday, 18 December 2020 at 19:14:25 UTC, Daren Scot Wilson wrote: So maybe beamui isn't ready for the real world. It's a one-off personal tool for image processing, maybe will go up on Github, so I don't need anything super-solid or well established. OTOH, if it's too much on the WIP side with lots of loose ends, it might be more work than my free time allows. At least, beamui appears to be more workable than dlangui which seems to have fallen away. Did you find a GUI library to work with? I'm in the same boat as you working on a tool for image processing in my free time. I always recommend gtkd. Its pretty good. See gtkdcoding.com for examples.
Re: Socket handle leak and active handle warning with Vibe-D
On Friday, 1 January 2021 at 22:07:28 UTC, Selim Ozel wrote: I created the simplest possible example as explained by the Vibe-D community in [1]. The exact source code of what I run is in [2]. On Windows I get a socket handle leak warning on shutdown with crtl+c from terminal after running the executable. [...] On Ubuntu 20.04 I get leaking drivers warning with the same process. [...] I really don't know what this is all about but it is at the core of my Vibe-D development. So any pointers you might have would be very helpful to me. Thanks in advance. S [1] https://vibed.org/blog/posts/a-scalable-chat-room-service-in-d [2] https://github.com/SelimOzel/vibe_noLeaks Add this to your dub.json file to fix it "versions": [ "VibeHighEventPriority" ] This issue should be fixed in next vibe.d release
Re: Recursively defined matcher function
On Sunday, 3 January 2021 at 18:26:44 UTC, Per Nordlöw wrote: alias Matcher = Match function(Matcher[] matchers...); but it errors as recursive alias declaration Preferrably I wanted a non-templated definition.
Re: Recursively defined matcher function
On Sunday, 3 January 2021 at 18:55:58 UTC, sighoya wrote: ``` alias matcherSignature(T:matcherSignature!T) = Matcher (T[] matchers...); ``` Yet, it is right: ``` alias matcherSignature(T:matcherSignature!T) = Matcher function(T[] matchers...); ``` But it didn't work likewise, you have to instantiate it infinitely in nesting order. I think you either need some kind of nominalism to state matcherSignature!T exists for any T or you need to end it after a certain depth: ``` struct theEnd {} template matcherSignature(T) if (T==matcherSignature!T || T==theEnd) { Matcher function(T[] matchers...) fp; } ```
Re: Recursively defined matcher function
On Sunday, 3 January 2021 at 18:49:40 UTC, sighoya wrote: ``` alias matcherSignature(T:matcherSignature!T) = T (T[] matchers...); ``` Ahhh, I meant this: ``` alias matcherSignature(T:matcherSignature!T) = Matcher (T[] matchers...); `` I think we would require proper singleton types to model this as: ``` matcherSignature(matcherSignature.type[] matcherSignatures ...) ``` and this: ``` Matcher matcherSignature(matcherSignature.type[] matcherSignatures...) ```
Re: Recursively defined matcher function
On Sunday, 3 January 2021 at 18:26:44 UTC, Per Nordlöw wrote: I've tried alias Matcher = Match function(Matcher[] matchers...); but it errors as recursive alias declaration The closest thing can I think of is: ``` alias matcherSignature(T:matcherSignature!T) = T (T[] matchers...); ``` I think we would require proper singleton types to model this as: ``` matcherSignature(matcherSignature.type[] matcherSignatures ...) ```
Recursively defined matcher function
How can I define a function type `Matcher` that takes an array of `Matcher`s and returns an instance of a `struct Match` defined as struct Match { @safe pure nothrow @nogc: static Match zero() { return typeof(return)(0); } static Match none() { return typeof(return)(_length.max); } /// Match length in number of UTF-8 chars or 0 if empty. @property uint length() { return _length; } bool opCast(U : bool)() const { return _length != _length.max; } this(size_t length) { assert(length <= _length.max); this._length = cast(typeof(_length))length; } const uint _length;// length == uint.max is no match } I've tried alias Matcher = Match function(Matcher[] matchers...); but it errors as recursive alias declaration
Re: D static library on Windows 64 problem
On Saturday, 2 January 2021 at 22:08:34 UTC, WhatMeWorry wrote: On Saturday, 2 January 2021 at 22:04:28 UTC, WhatMeWorry wrote: I'm stepping through the windows static library tutorial at http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial/CompilingLinkingD#Linkingmanually [...] Oops. used the manual example. Should be /LIBPATH:c:\dev\LibraryStudy\StaticLibrary\libfoobar If it doesn't say so on the wiki (haven't read), could you update it with your findings? Thanks!
Re: Tuple enumeration without integers or strings
On Sunday, 3 January 2021 at 13:36:57 UTC, Paul wrote: Is there an easy way for me to know when code is assessed / generated at compile time? For example, is indexing a constant compile time array compile time or run time? Or how about functions? The hashOf documentation does not seem to hint to being done at compile time. It's not what you do, but the context in which you do it. If a function must be evaluated at compile time, it will be. ``` string tellme() { if(__ctfe) return "Compile Time"; else return "Run time"; } void main() { writeln(tellme()); pragma(msg, tellme()); writeln(tellme()); } ``` Since the msg pragma is a compile-time construct, tellme *must* be evaluated at compile time. The calls to writeln are just normal function calls, therefore the calls to tellme happen at runtime. So any context where you replace a compile-time constant with a function call, you'll have CTFE (as long as it's possible [1]). It's common to use enum to force CTFE: enum s = tellme(); [1] https://dlang.org/spec/function.html#interpretation
Re: Tuple enumeration without integers or strings
On Sunday, 3 January 2021 at 06:05:48 UTC, frame wrote: The hash is also generated at compile time. Is there an easy way for me to know when code is assessed / generated at compile time? For example, is indexing a constant compile time array compile time or run time? Or how about functions? The hashOf documentation does not seem to hint to being done at compile time.
Re: D string to C struct fixed-size array
Your definition of Image is probably wrong. You may have missed a pointer (8 bytes).
Re: D string to C struct fixed-size array
On Sunday, 3 January 2021 at 09:28:55 UTC, rikki cattermole wrote: import std; void main() { int[] a = [1, 2, 3, 4, 5]; int[3] b; b[0 .. 3] = a[1 .. 4]; b.writeln; } Same principle, just remember to null terminate after slicing your dynamic array and assigning it to your static array. Thanks for the suggestion, however, it yields the same results as my "create new array and loop through string" attempt. That is to say, an incomplete filename is used when writing (saving) the image to disk. If it help, here is some of the actual code (using what I've understood from your sample): int main(string[] args) { ulong len; Image* image; /* a separate structure, which also has a char[MaxTextExtent] filename */ ImageInfo* imageInfo; /* another GraphicsMagick struct */ ExceptionInfo exception; InitializeMaigck(null); /* creates a ImageInfo with defaults */ imageInfo = CloneImageInfo(null); /* actual code has a check for args.length */ len = args[1].length; /* set the input filename */ imageInfo.filename[0 .. len] = args[1]; imageInfo.filename[len] = '\0'; /* read image from input file */ image = ReadImage(imageInfo, ); /* set the output filename */ len = args[2].length; image.filename[0 .. len] = args[2]; image.filename[len] = '\0'; /* write (save) image to disk */ WriteImage(imageInfo, image); /* memory cleanup skipped */ return 0; } The full code is really just a port of the `convert.c` example shown on the API page[0], [0]: http://www.graphicsmagick.org/api/api.html
Re: D string to C struct fixed-size array
import std; void main() { int[] a = [1, 2, 3, 4, 5]; int[3] b; b[0 .. 3] = a[1 .. 4]; b.writeln; } Same principle, just remember to null terminate after slicing your dynamic array and assigning it to your static array.
D string to C struct fixed-size array
Hi, I'm trying to create bindings to the GraphcicsMagick C library which has the following struct defined: #define MaxTextExtent 2053 typedef struct _Image { /* other members skipped */ char filename[MaxTextExtent]; } Image; In an `extern (C)` block I've "converted" the struct to D: enum MaxTextExtent = 2053; struct Image { /* other members skipped */ char[MaxTextExtent] filename; } The problem is trying to set the `filename` member since I can't directly use a D string. I've seen a post which is a similar issue[0], but adapting the code provides an error: static assert: "Cannot put a string into a char[2053]" I've also tried using `new char[MaxTextExtent]` and looping through the string to copy the characters over. This does compile, however, when trying to write the image to disk the provided filename is often a "stripped" version of when you want (e.g. "image.jpg" becomes "g"). [0]: https://forum.dlang.org/thread/lshnzqbfkrhfkliap...@forum.dlang.org