Thread overview
Thick bingings and Deimos
Jan 24, 2019
Victor Porton
Jan 24, 2019
rikki cattermole
Jan 24, 2019
Victor Porton
Jan 24, 2019
rikki cattermole
Jan 24, 2019
Neia Neutuladh
Jan 24, 2019
JN
Jan 24, 2019
Vladimir Panteleev
Jan 24, 2019
Vladimir Panteleev
January 24, 2019
I found: https://wiki.dlang.org/Deimos "Translated header should not require linkage of any D binary."

Thus it seems that I cannot create OO wrappers around C code like this:

struct Wrapper {
    this() { theclibrary_init(); }
    ~this() { theclibrary_finalize(); }
}

It is sad that I cannot do this in Deimos. What to do?
January 24, 2019
On 24/01/2019 11:48 PM, Victor Porton wrote:
> I found: https://wiki.dlang.org/Deimos "Translated header should not require linkage of any D binary."
> 
> Thus it seems that I cannot create OO wrappers around C code like this:
> 
> struct Wrapper {
>      this() { theclibrary_init(); }
>      ~this() { theclibrary_finalize(); }
> }
> 
> It is sad that I cannot do this in Deimos. What to do?

Deimos is a Github organization that was created prior to dub.
It was meant for collecting bindings to C libraries. So yes a wrapper which you're asking about would not be an appropriate addition to it.

You do not have to follow the rules of Deimos for your own libraries/bindings. But I would recommend heavily to separate the binding from the wrapper for cleaner code.
January 24, 2019
On Thursday, 24 January 2019 at 10:48:12 UTC, Victor Porton wrote:
> I found: https://wiki.dlang.org/Deimos "Translated header should not require linkage of any D binary."
>
> Thus it seems that I cannot create OO wrappers around C code like this:
>
> struct Wrapper {
>     this() { theclibrary_init(); }
>     ~this() { theclibrary_finalize(); }
> }
>
> It is sad that I cannot do this in Deimos. What to do?

The idea behind Deimos was to provide 1:1 (as much as possible) bindings to the C code, without any OO wrappers involved. However, Deimos was created before Dub and packages were really a thing. Nowadays, just publish a package to Dub package repository with your bindings. Just be clear in the description that it offers a wrapper over the original C library and it should be fine.
January 24, 2019
On Thursday, 24 January 2019 at 10:52:22 UTC, rikki cattermole wrote:
> You do not have to follow the rules of Deimos for your own libraries/bindings. But I would recommend heavily to separate the binding from the wrapper for cleaner code.

Huh? Create a separate module with just two-three structs and methods?

Are you REALLY super that binding and wrapper should be in different repos?
January 24, 2019
On 24/01/2019 11:55 PM, Victor Porton wrote:
> On Thursday, 24 January 2019 at 10:52:22 UTC, rikki cattermole wrote:
>> You do not have to follow the rules of Deimos for your own libraries/bindings. But I would recommend heavily to separate the binding from the wrapper for cleaner code.
> 
> Huh? Create a separate module with just two-three structs and methods?
> 
> Are you REALLY super that binding and wrapper should be in different repos?

Not so much different repos, just different packages so you have a clean separation. LuaD[0] is a good example even though it was created prior to dub.

[0] https://github.com/JakobOvrum/LuaD

January 24, 2019
On Thursday, 24 January 2019 at 10:54:53 UTC, JN wrote:
> The idea behind Deimos was to provide 1:1 (as much as possible) bindings to the C code, without any OO wrappers involved. However, Deimos was created before Dub and packages were really a thing. Nowadays, just publish a package to Dub package repository with your bindings. Just be clear in the description that it offers a wrapper over the original C library and it should be fine.

Placing bindings in Deimos and publishing them on Dub are orthogonal.

There are benefits to placing bindings in one place beyond the benefits provided by a Dub package:

https://wiki.dlang.org/Deimos#Rationale
January 24, 2019
On Thursday, 24 January 2019 at 10:48:12 UTC, Victor Porton wrote:
> I found: https://wiki.dlang.org/Deimos "Translated header should not require linkage of any D binary."
>
> Thus it seems that I cannot create OO wrappers around C code like this:
>
> struct Wrapper {
>     this() { theclibrary_init(); }
>     ~this() { theclibrary_finalize(); }
> }
>
> It is sad that I cannot do this in Deimos. What to do?

I updated https://wiki.dlang.org/Deimos with some clarifications.

Hope that helps.
January 24, 2019
On Thu, 24 Jan 2019 10:55:06 +0000, Victor Porton wrote:
> On Thursday, 24 January 2019 at 10:52:22 UTC, rikki cattermole wrote:
>> You do not have to follow the rules of Deimos for your own libraries/bindings. But I would recommend heavily to separate the binding from the wrapper for cleaner code.
> 
> Huh? Create a separate module with just two-three structs and methods?

Yes. That way, you can use a tool like dstep to produce the raw bindings, potentially even automatically, and have it overwrite the bindings-only module, without having to overwrite the hand-written thick bindings.

> Are you REALLY super that binding and wrapper should be in different repos?

A module is a D source file, not a repository. The hint is that you have to write "module foo.bar;" at the top of each source file.