C binding with D function

llaine via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 3 07:35:56 PDT 2016


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 
> initialized.
>
> Does the ruby gem have a way to automatically call a particular 
> setup and teardown function in the library? You could make init 
> and and finalize functions that are called. Those run the 
> Runtime.initialized and Runtime.finalize.
>
> Looking at their docs, I don't see an automatic one, but you 
> could do a ruby constructor/destructor in the wrapper that does 
> it for the end user.
>
> For the D string, either replace it with a C char* or try 
> defining a struct on teh ruby side to match it... but C string 
> is probably easiest.

Okay so your advice is to directly replace string str by char* str
and then call the runtime initialisation in my function?


More information about the Digitalmars-d-learn mailing list