Re: malloc(s)[0..s] vs cast(T)malloc(s)
On 10/14/20 1:15 PM, Jack wrote: >> auto x = malloc(s)[0..s]; > https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation Note that 'x' is passed to emplace() at that link and emplace() requires a slice. That's why the a slice is made from the pointer returned by malloc(). Ali
Compile-time function call with transformed parameters
Hi, Is there a way to make this in a nicer way without the string mixin? private auto generateVector(CT, alias fun, T...)(in T args){ static if(anyVector!T){ Vector!(CT, CommonVectorLength!T) res; static foreach(i; 0..res.length) res[i] = mixin("fun(", T.length.iota.map!(j => "args["~j.text~"].vectorAccess!i").join(','), ")"); return res; }else{ return fun(args); } } The mixin expands to: fun(args[0].vectorAccess!i, ..., args[$-1].vectorAccess!i) And vectorAccess is a function with a template int parameter (i). private auto vectorAccess(int idx, T)(in T a){ static if(isVector!T) return a[idx]; else return a; } I tried with staticMap, but that vectorAccess is a runtime thing. Other than that I have no idea. I'm 99% sure DLang has a nice thing for this, but can't find it yet. Maybe it is possible to put a thing like this -> [ args[0].vectorAccess!i ] into an AliasSeq and then give that inside the fun(), but how can I generate effectively an array of code? Thank you!
Re: Error on dub build - Trying Vibe-d for the first time
So, it did work... The problem was on me, I guess. I was using this example: https://tour.dlang.org/tour/en/dub/vibe-d It wasn't working at all... So I've changed to this one, and it did work. https://code.dlang.org/packages/vibe-d/0.9.2 I've used the first example, there are some differences to the one on tour.dlang. Thanks all for the support.
Re: malloc(s)[0..s] vs cast(T)malloc(s)
On Wednesday, 14 October 2020 at 20:15:39 UTC, Jack wrote: What's the difference between: import core.stdc.stdlib : malloc; auto x = malloc(s)[0..s]; and auto x = cast(T)malloc(s); ? I have been using the last but I saw in some code examples, like this[1] the first being used. What's the difference? in the first one bounds checking is performed, giving an error right away, right? whereas the cast would just turn the null into the class reference and manual check need to be done later. Is that the reason? [1]: https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation The difference is that the first version gives you a `void[]`, and the second version gives you a `T`. Neither version does any bounds checking. Generally, you'd use the first version if you don't yet know what kind of object is going to be stored in the allocated memory (for example, if you're writing an allocator[1]), and the second version if you do know the type. [1] https://dlang.org/phobos/std_experimental_allocator_building_blocks.html
Re: Why was new(size_t s) { } deprecated in favor of an external allocator?
On Wednesday, 14 October 2020 at 20:27:10 UTC, Jack wrote: What was the reasoning behind this decision? Andrei's std::allocator talk from a few years ago at cppcon covers this (amongst other things)
Why was new(size_t s) { } deprecated in favor of an external allocator?
What was the reasoning behind this decision?
malloc(s)[0..s] vs cast(T)malloc(s)
What's the difference between: import core.stdc.stdlib : malloc; auto x = malloc(s)[0..s]; and auto x = cast(T)malloc(s); ? I have been using the last but I saw in some code examples, like this[1] the first being used. What's the difference? in the first one bounds checking is performed, giving an error right away, right? whereas the cast would just turn the null into the class reference and manual check need to be done later. Is that the reason? [1]: https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation
Re: How do I make this function from module public?
On Wednesday, 14 October 2020 at 01:55:13 UTC, Adam D. Ruppe wrote: On Wednesday, 14 October 2020 at 01:46:11 UTC, Jack wrote: extern(C): int mul(int a, int b) { return a * b;} mark it `export` as well and then be sure you are compiling in this module as well, it must be included on the ldc command line along with wasm.d worked, thanks!
Re: Error on dub build - Trying Vibe-d for the first time
On Wednesday, 14 October 2020 at 15:27:46 UTC, Andre Pany wrote: On Wednesday, 14 October 2020 at 13:20:53 UTC, Bruno Rodrigues wrote: On Wednesday, 14 October 2020 at 01:32:34 UTC, Steven Schveighoffer wrote: [...] Thank you, Steve! It did work but none of the examples on the Vibe.d page are working with current D version... Some errors I got When executing with dub [...] When compiling (dub, dub build or dub build --force), I got a lot of deprecation errors [...] Please add this to your dub.json file: "versions": [ "VibeHighEventPriority" ] You may have to restart your pc 1 time. After that the issue should not occur anymore. (It is a known bug). Kind regards Andre Thanks, Andre! I'll try this solution later.
Re: Error on dub build - Trying Vibe-d for the first time
On Wednesday, 14 October 2020 at 18:08:40 UTC, H. S. Teoh wrote: On Wed, Oct 14, 2020 at 05:30:37PM +, Andre Pany via Digitalmars-d-learn wrote: On Wednesday, 14 October 2020 at 16:39:39 UTC, Imperatorn wrote: > On Wednesday, 14 October 2020 at 15:27:46 UTC, Andre Pany > wrote: [...] > > [...] [...] > Where is this documented? I dont know whether it is documented somewhere. It was asked multiple times in the forum therefore I remembered. Maybe it could be documented in the vibe.d github wiki or on the vibe.d website. But hopefully the bug is solved soon. [...] Yeah, this is a problem. Things like these need to be put in the docs in an easy-to-find way. Like collected in a Troubleshooting page or something. If a bug isn't filed yet, I'd file a bug on vibe.d so that this will get resolved instead of forgotten, and then it will bite the next newcomer all over again. T https://github.com/search?q=VibeHighEventPriority=issues It seems with eventcore 0.9.9 there was some fix, but I do not know whether this solves the bug or s.th. related to the bug. Kind regards Andre
Re: Error on dub build - Trying Vibe-d for the first time
On Wed, Oct 14, 2020 at 05:30:37PM +, Andre Pany via Digitalmars-d-learn wrote: > On Wednesday, 14 October 2020 at 16:39:39 UTC, Imperatorn wrote: > > On Wednesday, 14 October 2020 at 15:27:46 UTC, Andre Pany wrote: [...] > > > Please add this to your dub.json file: > > > "versions": [ "VibeHighEventPriority" ] > > > > > > You may have to restart your pc 1 time. After that the issue > > > should not occur anymore. (It is a known bug). [...] > > Where is this documented? > > I dont know whether it is documented somewhere. It was asked multiple > times in the forum therefore I remembered. > > Maybe it could be documented in the vibe.d github wiki or on the > vibe.d website. But hopefully the bug is solved soon. [...] Yeah, this is a problem. Things like these need to be put in the docs in an easy-to-find way. Like collected in a Troubleshooting page or something. If a bug isn't filed yet, I'd file a bug on vibe.d so that this will get resolved instead of forgotten, and then it will bite the next newcomer all over again. T -- Many open minds should be closed for repairs. -- K5 user
Re: Error on dub build - Trying Vibe-d for the first time
On Wednesday, 14 October 2020 at 16:39:39 UTC, Imperatorn wrote: On Wednesday, 14 October 2020 at 15:27:46 UTC, Andre Pany wrote: On Wednesday, 14 October 2020 at 13:20:53 UTC, Bruno Rodrigues wrote: On Wednesday, 14 October 2020 at 01:32:34 UTC, Steven Schveighoffer wrote: [...] Thank you, Steve! It did work but none of the examples on the Vibe.d page are working with current D version... Some errors I got When executing with dub [...] When compiling (dub, dub build or dub build --force), I got a lot of deprecation errors [...] Please add this to your dub.json file: "versions": [ "VibeHighEventPriority" ] You may have to restart your pc 1 time. After that the issue should not occur anymore. (It is a known bug). Kind regards Andre Where is this documented? I dont know whether it is documented somewhere. It was asked multiple times in the forum therefore I remembered. Maybe it could be documented in the vibe.d github wiki or on the vibe.d website. But hopefully the bug is solved soon. Kind regards Andre
Re: Error on dub build - Trying Vibe-d for the first time
On Wednesday, 14 October 2020 at 15:27:46 UTC, Andre Pany wrote: On Wednesday, 14 October 2020 at 13:20:53 UTC, Bruno Rodrigues wrote: On Wednesday, 14 October 2020 at 01:32:34 UTC, Steven Schveighoffer wrote: [...] Thank you, Steve! It did work but none of the examples on the Vibe.d page are working with current D version... Some errors I got When executing with dub [...] When compiling (dub, dub build or dub build --force), I got a lot of deprecation errors [...] Please add this to your dub.json file: "versions": [ "VibeHighEventPriority" ] You may have to restart your pc 1 time. After that the issue should not occur anymore. (It is a known bug). Kind regards Andre Where is this documented?
Re: Error on dub build - Trying Vibe-d for the first time
On Wednesday, 14 October 2020 at 13:20:53 UTC, Bruno Rodrigues wrote: On Wednesday, 14 October 2020 at 01:32:34 UTC, Steven Schveighoffer wrote: [...] Thank you, Steve! It did work but none of the examples on the Vibe.d page are working with current D version... Some errors I got When executing with dub [...] When compiling (dub, dub build or dub build --force), I got a lot of deprecation errors [...] Please add this to your dub.json file: "versions": [ "VibeHighEventPriority" ] You may have to restart your pc 1 time. After that the issue should not occur anymore. (It is a known bug). Kind regards Andre
Re: vibe.d / experience / feedback
Is there an example just more functional then skeleton http server ? Sending data to the server and back .
Re: vibe.d / experience / feedback
forms.
Re: vibe.d / experience / feedback
On Wednesday, 14 October 2020 at 12:29:24 UTC, Alaindevos wrote: One concept at a time. This is one of the simplest examples in vibe.d. I look for the code for the same functionality but without authentication/login. https://github.com/vibe-d/vibe.d/blob/master/examples/web/source/app.d Where are the @ lines explained ? While this is already a sophisticated example and you might look for a simpler one (app skeleton/http server) I really like this example. You can read the source code like a story and the comments actually described the purposes of the @ UDAs. (They are also new for me, I only use the WebSocket server part of Vibe.d so far). Kind regards Andre
Re: Error on dub build - Trying Vibe-d for the first time
On Wednesday, 14 October 2020 at 01:32:34 UTC, Steven Schveighoffer wrote: On 10/13/20 8:40 PM, Bruno Rodrigues wrote: So, I tried building a simple hello world with Vibe-d and got this error /usr/bin/ld: cannot find -lssl /usr/bin/ld: cannot find -lcrypto collect2: error: ld returned 1 exit status Error: linker exited with status 1 /usr/bin/dmd failed with exit code 1. I have absolutely no ideia what these libraries are. I'm using linux 20.04 The project was created with dub the same way the dependency was added. Thanks, this language seems to be really interesting. sudo apt-get install libssl-dev That should get you running. -Steve Thank you, Steve! It did work but none of the examples on the Vibe.d page are working with current D version... Some errors I got When executing with dub [main() INF] Listening for requests on http://[::]:8080/ Failed to listen on 0.0.0.0:8080 Hello, World: / Warning (thread: main): leaking eventcore driver because there are still active handles FD 6 (streamListen) FD 9 (streamSocket) Warning (thread: main): leaking eventcore driver because there are still active handles FD 6 (streamListen) FD 9 (streamSocket) When compiling (dub, dub build or dub build --force), I got a lot of deprecation errors /usr/include/dmd/phobos/std/format.d(3648,26): Deprecation: function std.typecons.Nullable!(Alternate).Nullable.get_ is deprecated - Implicit conversion with alias Nullable.get this will be removed after 2.096. Please use .get explicitly.
Re: vibe.d / experience / feedback
One concept at a time. This is one of the simplest examples in vibe.d. I look for the code for the same functionality but without authentication/login. https://github.com/vibe-d/vibe.d/blob/master/examples/web/source/app.d Where are the @ lines explained ?