Re: Calling C functions

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 26 June 2020 at 00:30:22 UTC, Denis wrote: I have a two questions about calling C functions from D. (1) When passing a D callback to a C function, is there a way to write the code without having to prefix the callback declaration with "extern(C)"? It's not a big deal adding the

Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
Downloading files over TLS. This seems that it's something that should be quite simple to do. My high level goals are cross-platform and easy distribution. I don't need anything fancy just a simple API like this: download("https://url.com;, "/local/file"); Because of these goals, I have a

Re: Arduino and MCU Support

2020-06-26 Thread Dukc via Digitalmars-d-learn
On Thursday, 25 June 2020 at 03:00:04 UTC, Dylan Graham wrote: I'm currently making an automatic transmission controller with Arduino. C++ just has too many traps that I keep falling into. Since stability is critical (if the code screws up at 100km/h I'm dead), I'd rather use a sane language

Re: Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 26 June 2020 at 11:10:27 UTC, ikod wrote: Hello, re `requests` - it uses dlopen (and variants for OSX and Windows, see https://github.com/ikod/dlang-requests/blob/master/source/requests/ssl_adapter.d#L50). The reason for dlopen is simple - compatibility with both openssl ver 1.0

Re: Downloading files over TLS

2020-06-26 Thread ikod via Digitalmars-d-learn
On Friday, 26 June 2020 at 11:41:27 UTC, Jacob Carlborg wrote: On Friday, 26 June 2020 at 11:10:27 UTC, ikod wrote: [...] Oh, it's that bad. That's disappointing. [...] I'm using a script (written in D) in my tool, DStep [1][2], to identify which versions of libclang is available and to

isInputRange not satisfied even if all individual conditions are satisfied

2020-06-26 Thread Johannes Loher via Digitalmars-d-learn
Recently, I read about problems regarding the API design of ranges (not being able to make them const, differences between class and struct based ranges etc.). One of the issues that came up what the fact that sometimes it is useful to use the class wrappers `InputRangeObject` etc. if you need to

Re: Downloading files over TLS

2020-06-26 Thread ikod via Digitalmars-d-learn
On Friday, 26 June 2020 at 10:12:09 UTC, Jacob Carlborg wrote: Downloading files over TLS. This seems that it's something that should be quite simple to do. My high level goals are cross-platform and easy distribution. I don't need anything fancy just a simple API like this:

Re: Downloading files over TLS

2020-06-26 Thread Kagamin via Digitalmars-d-learn
On Friday, 26 June 2020 at 10:12:09 UTC, Jacob Carlborg wrote: Downloading files over TLS. This seems that it's something that should be quite simple to do. My high level goals are cross-platform and easy distribution. I don't need anything fancy just a simple API like this:

Re: Downloading files over TLS

2020-06-26 Thread User via Digitalmars-d-learn
On Friday, 26 June 2020 at 10:12:09 UTC, Jacob Carlborg wrote: Windows: I don't know that much of this platform. * std.net.curl and basically all other options already mentioned relies on OpenSSL, which is not provided by the platform * SChannel. As far as I know, this the the platform

Re: Downloading files over TLS

2020-06-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 June 2020 at 10:12:09 UTC, Jacob Carlborg wrote: * Arsd [4]. Relies on OpenSSL Yeah, I've been wanting to change that and use the native apis for years but like I just haven't been able to figure out the documentation of them. Though for plain download, on Windows there's a

Unused template arguments; what type to use?

2020-06-26 Thread drathier via Digitalmars-d-learn
How can I tell the compiler that I will never create a value of type X, while still being able to write code that uses it? Using void as a template parameter is where I started, but I still need to be able to declare variables inside this unreachable function, like `T foo;` even when `T ==

Re: Calling C functions

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 18:54, Denis wrote: OK, now this makes sense. I tested calling the same callback function directly from D: it compiled and worked correctly. So at least prefixing the callback function with `extern(C)` doesn't prevent the rest of the D program from calling it too. No, of

How to send ownerTid into a parallel foreach loop?

2020-06-26 Thread adnan338 via Digitalmars-d-learn
I have a list of files to download, and I want to download them in parallel. At the end of each of those parallel download I want to send the main thread a message from the parallel loop. import std.concurrency, std.parallelism; string[] files = ["a", "b", "c"]; void download(string[] links)

Re: Calling C functions

2020-06-26 Thread Denis via Digitalmars-d-learn
On Friday, 26 June 2020 at 08:15:27 UTC, Jacob Carlborg wrote: On Friday, 26 June 2020 at 00:30:22 UTC, Denis wrote: extern(C) void cfunc(void function(int)); extern(C) void dcallback(int x) {...} <-- Why extern(C)? cfunc(); Can this be rewritten, dropping the prefix from the

Re: Unused template arguments; what type to use?

2020-06-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 26, 2020 at 01:40:57PM +, Simen Kjærås via Digitalmars-d-learn wrote: > On Friday, 26 June 2020 at 13:21:25 UTC, drathier wrote: > > How can I tell the compiler that I will never create a value of type > > X, while still being able to write code that uses it? Using void as > > a

Re: Recursive delegate inside template?

2020-06-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 26, 2020 at 02:12:00PM +, drathier via Digitalmars-d-learn wrote: > I'm trying to get this to compile, without much luck: > > ``` > bool foo() > { > template fn(A) > { > A delegate(A) fn; > fn = delegate A(A a) > { > return fn(a); >

Re: Recursive delegate inside template?

2020-06-26 Thread drathier via Digitalmars-d-learn
On Friday, 26 June 2020 at 15:10:07 UTC, Adam D. Ruppe wrote: On Friday, 26 June 2020 at 14:12:00 UTC, drathier wrote: I'm trying to get this to compile, without much luck: You might be able to make it a function: bool foo() { auto fn(A)() { A delegate(A) fn; fn =

Re: Unused template arguments; what type to use?

2020-06-26 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 26 June 2020 at 13:21:25 UTC, drathier wrote: How can I tell the compiler that I will never create a value of type X, while still being able to write code that uses it? Using void as a template parameter is where I started, but I still need to be able to declare variables inside

Re: isInputRange not satisfied even if all individual conditions are satisfied

2020-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.06.20 15:35, ag0aep6g wrote: `isInputRange!R` fails because it has no knowledge of your free `empty` function. Without `empty`, `R` is obviously not a range. To be clear: It's the same with `front` and `popFront`. You can't implement any range primitives as free functions. It only

Re: Recursive delegate inside template?

2020-06-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 June 2020 at 14:12:00 UTC, drathier wrote: I'm trying to get this to compile, without much luck: You might be able to make it a function: bool foo() { auto fn(A)() { A delegate(A) fn; fn = delegate A(A a) { return fn(a); };

Re: Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 14:43, User wrote: It is possible to statically link libcurl into your application. No need to use OpenSSL as libcurl can be built with SChannel. That sounds good. It looks like I remembered wrong. std.net.curl uses `dlopen` on libcurl, not OpenSSL. This might be less of an

Re: Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 15:16, Adam D. Ruppe wrote: Yeah, I've been wanting to change that and use the native apis for years but like I just haven't been able to figure out the documentation of them. That would be nice. That's the problem of everything Apple makes. Kinda drives me nuts trying to keep

Re: isInputRange not satisfied even if all individual conditions are satisfied

2020-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 26.06.20 15:09, Johannes Loher wrote: import std.meta : allSatisfy, staticMap; import std.traits : allSameType; import std.range : isInputRange, ElementType, empty; [...] @property bool empty(TypeArgs...)(auto ref scope SumType!(TypeArgs) r) if (allSatisfy!(isInputRange, TypeArgs)

Re: isInputRange not satisfied even if all individual conditions are satisfied

2020-06-26 Thread Johannes Loher via Digitalmars-d-learn
Am 26.06.20 um 15:35 schrieb ag0aep6g: > `isInputRange!R` fails because it has no knowledge of your free `empty` > function. Without `empty`, `R` is obviously not a range. Ah, OK, that makes sense. It's kind of sad though because it really limits the extensibility of existing types with UFCS. Do

Re: isInputRange not satisfied even if all individual conditions are satisfied

2020-06-26 Thread Paul Backus via Digitalmars-d-learn
On Friday, 26 June 2020 at 13:53:46 UTC, Johannes Loher wrote: Am 26.06.20 um 15:35 schrieb ag0aep6g: `isInputRange!R` fails because it has no knowledge of your free `empty` function. Without `empty`, `R` is obviously not a range. Ah, OK, that makes sense. It's kind of sad though because it

Recursive delegate inside template?

2020-06-26 Thread drathier via Digitalmars-d-learn
I'm trying to get this to compile, without much luck: ``` bool foo() { template fn(A) { A delegate(A) fn; fn = delegate A(A a) { return fn(a); }; } return fn!(bool)(true); } ``` What am I missing here? How can I define a recursive

Re: Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 14:41, Kagamin wrote: Maybe just start wget or something like that? The point was to avoid runtime dependencies. Since you want the latest certificate storage, you intend to support only the latest system. Many root certificates will timeout now. I didn't say the latest