digitalmars.D.learn - How do I call a C++ struct default constructor from D?
- Atila Neves (10/10) Feb 07 2017 I can declare a C++ struct like so:
- kinke (4/14) Feb 07 2017 I'm afraid there's no way out. I summarized some of my C++
- Atila Neves (9/26) Feb 07 2017 Ugh, I was afraid of that. I ended up having to write (!) a C++
I can declare a C++ struct like so: extern(C++, mynamespace) struct Foo { //... } But... I don't want to repeat the initialisation code for that struct's default constructor. I can't declare one in D because D doesn't allow default constructors for structs. What's my way out? Thanks, Atila
Feb 07 2017
On Tuesday, 7 February 2017 at 10:15:09 UTC, Atila Neves wrote:I can declare a C++ struct like so: extern(C++, mynamespace) struct Foo { //... } But... I don't want to repeat the initialisation code for that struct's default constructor. I can't declare one in D because D doesn't allow default constructors for structs. What's my way out? Thanks, AtilaI'm afraid there's no way out. I summarized some of my C++ interop findings incl. default constructor here: http://forum.dlang.org/thread/nqxsdehlydizatoprrax forum.dlang.org
Feb 07 2017
On Tuesday, 7 February 2017 at 10:46:24 UTC, kinke wrote:On Tuesday, 7 February 2017 at 10:15:09 UTC, Atila Neves wrote:Ugh, I was afraid of that. I ended up having to write (!) a C++ function that returned the default-initialised struct and called that from D. It got uglier soon after... I've only every done trivial C++ integration before. As soon as I tried something "real" it all broke down incredibly fast. Probably going to have to file some bugs on name mangling. AtilaI can declare a C++ struct like so: extern(C++, mynamespace) struct Foo { //... } But... I don't want to repeat the initialisation code for that struct's default constructor. I can't declare one in D because D doesn't allow default constructors for structs. What's my way out? Thanks, AtilaI'm afraid there's no way out. I summarized some of my C++ interop findings incl. default constructor here: http://forum.dlang.org/thread/nqxsdehlydizatoprrax forum.dlang.org
Feb 07 2017
On Tuesday, 7 February 2017 at 13:37:01 UTC, Atila Neves wrote:On Tuesday, 7 February 2017 at 10:46:24 UTC, kinke wrote: I've only every done trivial C++ integration before. As soon as I tried something "real" it all broke down incredibly fast. Probably going to have to file some bugs on name mangling. AtilaPerhaps this video will help https://www.youtube.com/watch?v=HTgJaRRfLPk
Feb 07 2017
On Tuesday, 7 February 2017 at 13:37:01 UTC, Atila Neves wrote: Here still example https://pp.vk.me/c636630/v636630885/46579/neSdIip1ySI.jpg
Feb 07 2017
On Tuesday, 7 February 2017 at 14:26:11 UTC, MGW wrote:On Tuesday, 7 February 2017 at 13:37:01 UTC, Atila Neves wrote: Here still example https://pp.vk.me/c636630/v636630885/46579/neSdIip1ySI.jpgI'm sorry for being offensive, but... Of course, and the next step will be pragma mangle on D function to map it to correct ctor, then we call malloc(oops, how do we know correct class instance size?), then we call placement new from C++ RT on malloc'd memory, easy. Oh and then we also should call pragma mangled dtor, we do want no mem leaks, right? Now, sorry for being sarcastic but this is not the way, just imagine making all this new wrappers for every ctor manually for any serious project like Qt, PhysX, Bullet Physics, or FBX or Alembic SDK... Ok, and then we are standing at the point of supporting the future releases and changes
Feb 08 2017