www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Thick bingings and Deimos

reply Victor Porton <porton narod.ru> writes:
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?
Jan 24 2019
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
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.
Jan 24 2019
parent reply Victor Porton <porton narod.ru> writes:
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?
Jan 24 2019
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
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
Jan 24 2019
prev sibling parent Neia Neutuladh <neia ikeran.org> writes:
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.
Jan 24 2019
prev sibling next sibling parent reply JN <666total wp.pl> writes:
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.
Jan 24 2019
parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
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
Jan 24 2019
prev sibling parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
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.
Jan 24 2019