digitalmars.D.learn - problems with swig generated code
- Martin DeMello (14/14) Aug 28 2019 I'm trying to add a D binding to a C++ project that already has a
- DanielG (3/3) Sep 01 2019 Do you know whether SWIG's D generator is even being maintained?
- Martin DeMello (7/10) Sep 03 2019 I didn't realise that :( It was included in the current release
- Laeeth Isharc (32/44) Sep 03 2019 I think DPP can call constructors. YMMV.
- Ernesto Castellotti (50/62) Sep 12 2019 Not true, with the core.stdcpp.new_ module it is possible to
I'm trying to add a D binding to a C++ project that already has a swig definition file; you can see my attempt here: https://github.com/martindemello/quackle/tree/d/bindings but trying to run dmd over the generated file errors with: $ dmd quackle.d quackle.d(105): Error: undefined identifier SwigPendingException in module quackle_im, did you mean struct SwigPendingException? Looking at quackle_im.d, SwigPendingException is defined via package struct SwigPendingException { ... } and used in quackle.d via if (quackle_im.SwigPendingException.isPending) throw quackle_im.SwigPendingException.retrieve();
Aug 28 2019
Do you know whether SWIG's D generator is even being maintained? I've searched for it on the forums in the past and got the impression that it's outdated.
Sep 01 2019
On Sunday, 1 September 2019 at 11:19:11 UTC, DanielG wrote:Do you know whether SWIG's D generator is even being maintained? I've searched for it on the forums in the past and got the impression that it's outdated.I didn't realise that :( It was included in the current release of swig, so I figured it was maintained. It's pretty sad if it's not, because trying to access C++ libraries directly from D has some limitations (most notably not being able to create new C++ objects from D) and swig would have let things just work.
Sep 03 2019
On Tuesday, 3 September 2019 at 20:03:37 UTC, Martin DeMello wrote:On Sunday, 1 September 2019 at 11:19:11 UTC, DanielG wrote:I think DPP can call constructors. YMMV. We are working on a little project I started as another step in the eternal personal hackathon. Libclang isn't my cup of tea. It's almost very cool but they put in whatever the guy needed and so it's inconsistent but your alternative is code that breaks things between breakfast and teatime. Cling is used at CERN and I found libcling more pleasant. I only wrapped the cppyy fork but that actually allows you to reflect at runtime on a lot. From our DSL at work I can include a header, instantiate a templated type, create an instance of the class and call a method on it. Can, but it's not what I would call fun. I didn't yet get time to wrap the rest of the interpreter. But the idea is to make a tool for wrapping c++ via simpler extern (C++). If one isn't quite sure upfront what will work and not then it's much more pragmatic. I can't see how it won't work but we will know in a week or two. My first version is here. https://github.com/kaleidicassociates/cpp-reflect-d There is another route people don't think of. Calypso can introspect on C++ too. You might not want to use it in production but you don't need to. Either I guess you could use it to generate wrappers or you can use it to replace a chunk of cpp code. The surface area of a method must be larger than thr surface area of a chunk. Well chosen then it's easy to write glue code semi automatically. But it's nice to be able to replace a method at a time and have working code at every step. You don't need to trust Calypso in production to be able to use it for this purpose.Do you know whether SWIG's D generator is even being maintained? I've searched for it on the forums in the past and got the impression that it's outdated.I didn't realise that :( It was included in the current release of swig, so I figured it was maintained. It's pretty sad if it's not, because trying to access C++ libraries directly from D has some limitations (most notably not being able to create new C++ objects from D) and swig would have let things just work.
Sep 03 2019
On Tuesday, 3 September 2019 at 20:03:37 UTC, Martin DeMello wrote:On Sunday, 1 September 2019 at 11:19:11 UTC, DanielG wrote:Not true, with the core.stdcpp.new_ module it is possible to allocate the memory to create an object directly from D! Just allocate the memory (YourCPPClass.sizeof) and call std.conv.emplace to use the constructor If you want there is also a wrapper that simplifies the operation https://github.com/ErnyTech/CPPNew A small example: // test.cpp #include <iostream> class Test { public: Test(int); ~Test(); void set(int); void print(); private: int a; }; Test::Test(int number) { this->set(number); } Test::~Test() { std::cout << "Destructor called" << std::endl; } void Test::set(int number) { this->a = number; } void Test::print() { std::cout << this->a << std::endl; } // test.d extern(C++) { class Test { final this(int); final ~this(); final void set(int); final void print(); } } void main() { import cppnew : CPPNew; import cppnew : CPPDelete; auto test = CPPNew!Test(67); test.print(); // will print 67 test.setNumber(12); test.print(); // will print 12 CPPDelete(test); // will print Destructor called }Do you know whether SWIG's D generator is even being maintained? I've searched for it on the forums in the past and got the impression that it's outdated.I didn't realise that :( It was included in the current release of swig, so I figured it was maintained. It's pretty sad if it's not, because trying to access C++ libraries directly from D has some limitations (most notably not being able to create new C++ objects from D) and swig would have let things just work.
Sep 12 2019