Re: Passing refs with delegates

2016-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 08/02/2016 07:55 PM, Mark J Twain wrote: It's nice to be able to pass delegates and functions as callbacks. A nice feature is something like R foo(R,Args...)(R function(Args) callback, Args args) { return callback(args); } There are two problems with this. One is that type deduction

Re: q about bindings to C (noob)

2016-08-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-08-03 10:27, RomanZ wrote: version(RefOut) extern(C) void fun(out int input, ref in output); else extern(C) void fun( /*[out]*/ int* input, const(float)* output); version = RefOut; void main() { int input; float output; fun( input, output ); // work fine; is it

q about bindings to C (noob)

2016-08-03 Thread RomanZ via Digitalmars-d-learn
version(RefOut) extern(C) void fun(out int input, ref in output); else extern(C) void fun( /*[out]*/ int* input, const(float)* output); version = RefOut; void main() { int input; float output; fun( input, output ); // work fine; is it correct binding? or

Re: Indexing with an arbitrary type

2016-08-03 Thread Alex via Digitalmars-d-learn
On Monday, 1 August 2016 at 16:09:50 UTC, Alex wrote: On Monday, 1 August 2016 at 15:51:58 UTC, Jonathan M Davis wrote: template isIndexable(I, T) { enum isIndexable = __traits(compiles, T.init[I.init]); } As a last question afterwards: Is it possible to create such an isIndexable

Re: C binding with D function

2016-08-03 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:08:51 UTC, llaine wrote: So basically I have to create wrapper.c ? Yes, but you should write it in D. Runtime initialization is at https://dlang.org/phobos/core_runtime.html#.Runtime

Re: C binding with D function

2016-08-03 Thread llaine via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:08:51 UTC, llaine wrote: On Wednesday, 3 August 2016 at 14:58:04 UTC, bachmeier wrote: On Wednesday, 3 August 2016 at 15:08:51 UTC, llaine wrote: by switching my file to just this extern(C) { char* foo(char* str) { return str; } } It works.

Re: C binding with D function

2016-08-03 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:56:34 UTC, llaine wrote: Okay on stack overflow, they are not using ffi but dl. I tried changing ffi to dl, it's the same don't work unfortunatly. That's about as far as I can go without having it set up on my machine. The procedure should be the same as I

Re: C binding with D function

2016-08-03 Thread llaine via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:24:56 UTC, llaine wrote: On Wednesday, 3 August 2016 at 15:14:24 UTC, Kagamin wrote: After digging a bit more, I get a different error. import std.stdio; import core.runtime; extern(C) { void initialize() { Runtime.initialize(); } void

Re: q about bindings to C (noob)

2016-08-03 Thread RomanZ via Digitalmars-d-learn
thanks.

Re: C binding with D function

2016-08-03 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:24:56 UTC, llaine wrote: On Wednesday, 3 August 2016 at 15:14:24 UTC, Kagamin wrote: On Wednesday, 3 August 2016 at 15:08:51 UTC, llaine wrote: So basically I have to create wrapper.c ? Yes, but you should write it in D. Runtime initialization is at

Re: C binding with D function

2016-08-03 Thread llaine via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:47:48 UTC, bachmeier wrote: On Wednesday, 3 August 2016 at 15:24:56 UTC, llaine wrote: On Wednesday, 3 August 2016 at 15:14:24 UTC, Kagamin wrote: On Wednesday, 3 August 2016 at 15:08:51 UTC, llaine wrote: So basically I have to create wrapper.c ? Yes, but

Re: C binding with D function

2016-08-03 Thread llaine via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 14:02:12 UTC, Adam D. Ruppe wrote: On Wednesday, 3 August 2016 at 13:44:46 UTC, llaine wrote: void puts(string str) { writeln(str); } A D string isn't the same as a C string, so your params won't work as-is, and writeln requires the D runtime to be

Re: DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?

2016-08-03 Thread Kagamin via Digitalmars-d-learn
There's also official armv7hf release https://github.com/ldc-developers/ldc/releases

Re: Indexing with an arbitrary type

2016-08-03 Thread Alex via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 14:23:59 UTC, Jonathan M Davis wrote: On Wednesday, August 03, 2016 09:21:13 Alex via Digitalmars-d-learn wrote: On Monday, 1 August 2016 at 16:09:50 UTC, Alex wrote: > On Monday, 1 August 2016 at 15:51:58 UTC, Jonathan M Davis > wrote: > template isIndexable(I,

Re: C binding with D function

2016-08-03 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 14:01:34 UTC, llaine wrote: On Wednesday, 3 August 2016 at 13:49:36 UTC, bachmeier wrote: Probably because you need the D runtime. One way is to import core.runtime and call Runtime.initialize(). Where should I call this Runtime.initialize() ? Does the

Re: C binding with D function

2016-08-03 Thread llaine via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:14:24 UTC, Kagamin wrote: On Wednesday, 3 August 2016 at 15:08:51 UTC, llaine wrote: So basically I have to create wrapper.c ? Yes, but you should write it in D. Runtime initialization is at https://dlang.org/phobos/core_runtime.html#.Runtime Okay I tried

Re: Indexing with an arbitrary type

2016-08-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 03, 2016 09:21:13 Alex via Digitalmars-d-learn wrote: > On Monday, 1 August 2016 at 16:09:50 UTC, Alex wrote: > > On Monday, 1 August 2016 at 15:51:58 UTC, Jonathan M Davis > > wrote: > > template isIndexable(I, T) > > { > > > > enum isIndexable = __traits(compiles,

Re: C binding with D function

2016-08-03 Thread llaine via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 14:58:04 UTC, bachmeier wrote: On Wednesday, 3 August 2016 at 14:01:34 UTC, llaine wrote: On Wednesday, 3 August 2016 at 13:49:36 UTC, bachmeier wrote: Probably because you need the D runtime. One way is to import core.runtime and call Runtime.initialize().

Re: Initialize array of objects not work

2016-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 08/03/2016 10:58 AM, Andre Pany wrote: > I try to initialize an array of objects. The methods (linear/equals/) > returns object of different classes, but all implement a common > interface "Element". > > Element[] elements = >

Re: Indexing with an arbitrary type

2016-08-03 Thread Alex via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 14:46:25 UTC, Alex wrote: On Wednesday, 3 August 2016 at 14:23:59 UTC, Jonathan M Davis wrote: But it should. Just found this: https://www.sgi.com/tech/stl/StrictWeakOrdering.html which should be fulfilled by a type, which can be used as a key. So, in my

Re: Indexing with an arbitrary type

2016-08-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 03, 2016 16:42:18 Alex via Digitalmars-d-learn wrote: > On Wednesday, 3 August 2016 at 14:46:25 UTC, Alex wrote: > > On Wednesday, 3 August 2016 at 14:23:59 UTC, Jonathan M Davis > > wrote: > > > > But it should. > > > > Just found this: > >

Re: C binding with D function

2016-08-03 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:56:34 UTC, llaine wrote: Okay on stack overflow, they are not using ffi but dl. I tried changing ffi to dl, it's the same don't work unfortunatly. This FFI example calls an init function from a library:

alias to function literal, call without () not possible

2016-08-03 Thread Andre Pany via Digitalmars-d-learn
Hi, I just stumbled over this behavior. I am not sure whether the behavior is correct or not. alias foo = () => new Object; void bar(Object o){} void main() { auto n1 = foo; bar(foo); } While first line in main is working fine, second line does not compile due to missing ().

Initialize array of objects not work

2016-08-03 Thread Andre Pany via Digitalmars-d-learn
Hi, I try to initialize an array of objects. The methods (linear/equals/) returns object of different classes, but all implement a common interface "Element". Element[] elements = quadraticCoefficient(1)~linearCoefficient(2)~equals()~constant(1); I tried different casts and different

Re: alias to function literal, call without () not possible

2016-08-03 Thread Anonymouse via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 17:16:10 UTC, Andre Pany wrote: Hi, I just stumbled over this behavior. I am not sure whether the behavior is correct or not. [...] alias foo = () => new Object; ...is an alias for a delegate/function returning an Object. It is analogous to alias foo = () {

Re: Initialize array of objects not work

2016-08-03 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 18:34:02 UTC, Ali Çehreli wrote: On 08/03/2016 10:58 AM, Andre Pany wrote: > [...] (linear/equals/) > [...] common > [...] quadraticCoefficient(1)~linearCoefficient(2)~equals()~constant(1); [...] Thanks a lot Ali. Kind regards André

Re: alias to function literal, call without () not possible

2016-08-03 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 18:15:23 UTC, Anonymouse wrote: On Wednesday, 3 August 2016 at 17:16:10 UTC, Andre Pany wrote: [...] [...] ...is an alias for a delegate/function returning an Object. It is analogous to [...] [...] ...is a function accepting an Object parameter. In main

C binding with D function

2016-08-03 Thread llaine via Digitalmars-d-learn
Hi guys, I'm trying to make a bridge between D and ruby with a gem called ffi. It's basically a loading/binding library that grab C function and make them callable from Ruby code. As you might already understand, i'm trying to develop extensions using D and uses them in Ruby. I tried to

Re: Indexing with an arbitrary type

2016-08-03 Thread Alex via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 17:56:54 UTC, Jonathan M Davis wrote: int is comparable, but it's not going to index float[string]. Only a string is going to do that. Similarly, long is comparable, but on a 32-bit system, it won't index int[], because it's larger than size_t, which is the

Re: C binding with D function

2016-08-03 Thread lobo via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 15:41:55 UTC, llaine wrote: void foo(string str) { writeln(str); } shouldn't foo be: void foo(char* str) { import std.string; writeln(str.fromStringz); } bye, lobo

Re: C binding with D function

2016-08-03 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 13:44:46 UTC, llaine wrote: Hi guys, I'm trying to make a bridge between D and ruby with a gem called ffi. It's basically a loading/binding library that grab C function and make them callable from Ruby code. As you might already understand, i'm trying to

Re: C binding with D function

2016-08-03 Thread llaine via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 13:49:36 UTC, bachmeier wrote: Probably because you need the D runtime. One way is to import core.runtime and call Runtime.initialize(). Where should I call this Runtime.initialize() ?

Re: C binding with D function

2016-08-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 13:44:46 UTC, llaine wrote: void puts(string str) { writeln(str); } A D string isn't the same as a C string, so your params won't work as-is, and writeln requires the D runtime to be initialized. Does the ruby gem have a way to automatically call a

Re: Passing refs with delegates

2016-08-03 Thread Mark J Twain via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 08:12:00 UTC, Ali Çehreli wrote: On 08/02/2016 07:55 PM, Mark J Twain wrote: [...] I didn't know one could use 'auto ref' in this case but the following simple test works: auto foo(Func, Args...)(Func callback, auto ref Args args) { return callback(args);