October 17, 2021

On Sunday, 10 October 2021 at 17:14:30 UTC, Adam Ruppe wrote:

>

On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote:

>

The language subset "BetterC" is required for calling D functions from C though.

This is false.

You can use any D features when calling it from C, you just need to provide an init and term function that is called from C that runtime initialize and terminate for the full experience.

>

BetterC helper librarys like Tanya or Tango do exist.

I don't know tanya, but Tango has absolutely nothing to do with betterC. It is a set of classes that use the full runtime.

That's nice!

Do you have a link for more information how to initialize the D runtime? I just wondered about that because I thought it actually shouldn't be much more difficult than just linking the runtime into the foreign-language compiled program. I didn't find information on that. Maybe I didn't search long enough.

October 18, 2021

On Sunday, 17 October 2021 at 23:07:15 UTC, Elmar wrote:

>

Do you have a link for more information how to initialize the D runtime?

Export a function that calls this:
http://druntime.dpldocs.info/core.runtime.Runtime.initialize.html

And also export a function that calls this:
http://druntime.dpldocs.info/core.runtime.Runtime.terminate.html

And tell the user to call those when they load/unload the library. (It is pretty common for C libraries to require explicit init/term calls so they should be used to it.)

They refcount internally so it is ok to call multiple times, just make sure the init and term are always paired.

(btw the druntime actually exports them as extern(C) rt_init/rt_term but I'd still recommend you do your own anyway. if you do have extra work to do you can just do it there, and it can use whatever your lib naming conventions are. and besides im not sure if the extern(C) things are specified stable (even though they have been for as long as i can remember), whereas doing your own thing that import core.runtime; return Runtime.initalize; is. )

1 2
Next ›   Last »