Re: C binding with D function

2016-08-05 Thread Adam D. Ruppe via Digitalmars-d-learn
A fun project might be to use D's reflection to automatically generate any C binding translators to a nice D interface and the Ruby file to access it. I did something similar back in the day for PHP and JavaScript... it would be kinda tricky to do it with best efficiency, but getting it to wo

Re: C binding with D function

2016-08-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 4 August 2016 at 13:14:34 UTC, llaine wrote: Here is my repo https://github.com/llaine/ruby-dlang FYI: to!string is kinda slow. If you want to do a fast blank, you should avoid conversions actually, I'm surprised it is faster than the native Ruby one at all.

Re: C binding with D function

2016-08-05 Thread llaine via Digitalmars-d-learn
On Thursday, 4 August 2016 at 23:35:55 UTC, bachmeier wrote: On Thursday, 4 August 2016 at 17:11:04 UTC, Adam D. Ruppe wrote: Happy that you guys put this on the Wiki !!

Re: C binding with D function

2016-08-04 Thread bachmeier via Digitalmars-d-learn
On Thursday, 4 August 2016 at 17:11:04 UTC, Adam D. Ruppe wrote: On Thursday, 4 August 2016 at 14:46:33 UTC, bachmeier wrote: I'd like to put this example on the wiki unless you think there is a reason to not do so. cool. I'll prolly slap it in this week in D soon too (I've been kinda short o

Re: C binding with D function

2016-08-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 4 August 2016 at 14:46:33 UTC, bachmeier wrote: I'd like to put this example on the wiki unless you think there is a reason to not do so. cool. I'll prolly slap it in this week in D soon too (I've been kinda short on material lately!)

Re: C binding with D function

2016-08-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 4 August 2016 at 13:14:34 UTC, llaine wrote: I saw that your compiling using dmd with all thoses options. Can you explain me what is the benefit of using this ? I just don't use dub, I don't see the benefit of it, but if it works for you, cool!

Re: C binding with D function

2016-08-04 Thread Martin Tschierschke via Digitalmars-d-learn
On Thursday, 4 August 2016 at 12:14:48 UTC, Adam D. Ruppe wrote: On Thursday, 4 August 2016 at 10:36:05 UTC, llaine wrote: Any idea how can I call them ? Just like any other function. Consider this: [...] Compile [...] hi from D, Ruby user! Thank you a lot!!! I want to use some vibe.d r

Re: C binding with D function

2016-08-04 Thread bachmeier via Digitalmars-d-learn
On Thursday, 4 August 2016 at 12:14:48 UTC, Adam D. Ruppe wrote: On Thursday, 4 August 2016 at 10:36:05 UTC, llaine wrote: Any idea how can I call them ? Just like any other function. Consider this: I'd like to put this example on the wiki unless you think there is a reason to not do so.

Re: C binding with D function

2016-08-04 Thread ketmar via Digitalmars-d-learn
On Thursday, 4 August 2016 at 13:14:34 UTC, llaine wrote: I saw that your compiling using dmd with all thoses options. Can you explain me what is the benefit of using this ? very simple: avoiding dub. Adam is not using it.

Re: C binding with D function

2016-08-04 Thread llaine via Digitalmars-d-learn
On Thursday, 4 August 2016 at 12:14:48 UTC, Adam D. Ruppe wrote: On Thursday, 4 August 2016 at 10:36:05 UTC, llaine wrote: Any idea how can I call them ? Just like any other function. Consider this: -- hi from D, Ruby user! Wow thank you Adam, it's pretty impressive. I saw that yo

Re: C binding with D function

2016-08-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 4 August 2016 at 10:36:05 UTC, llaine wrote: Any idea how can I call them ? Just like any other function. Consider this: -- // i.d import std.stdio; extern(C) void hello() { writeln("hi from D"); } -- # d.rb require 'rubygems' require 'ffi' module DIn

Re: C binding with D function

2016-08-04 Thread llaine via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 16:09:15 UTC, bachmeier wrote: 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

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 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: https://github.com/ffi/ffi/blob/ce0e712bcb8876620e10c89

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 sp

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 y

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 https://

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 foo(string

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 t

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. But

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(). Wh

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 second

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 in

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 pa

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 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 develo