C binding with D function

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 3 07:02:12 PDT 2016


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.



More information about the Digitalmars-d-learn mailing list