Papierkorb / bindgen

Binding and wrapper generator for C/C++ libraries
GNU General Public License v3.0
179 stars 18 forks source link

Issues wrapping namespaced classes #67

Closed adamcreekroad closed 4 years ago

adamcreekroad commented 4 years ago

I'm having some issues trying to create bindings for the PoDoFo library - everything is name-spaced under PoDoFo. I'm mainly having issues with classes.

If I use the namespace in the config, I have two issues (that I've found):

podofo.yml

module: Podofo # I also have issues if this is the same as the actual namespace

classes:
  PoDoFo::PdfDocument: Document
  PoDoFo::PdfMemDocument: MemDocument
  PoDoFo::PdfStreamedDocument: StreamedDocument

src/podofo/binding.cr

module Podofo
  ...
  class Document
    ...
  end

  class MemDocument
    ...
  end

  class StreamedDocument
    ...
  end
end

ext/podofo_binding.cpp

struct BgInherit_PdfMemDocument : public PoDoFo::PdfMemDocument {
  using PoDoFo::PdfMemDocument::PoDoFo::PdfMemDocument;

If I manually edit the generated code to fix these issues I can run crystal code using the bindings.

If I don't use the namespace, the inheritance is detected but the cpp bindings are incorrect since the namespace isn't used

podofo.yml

module: Podofo

classes:
  PdfDocument: Document
  PdfMemDocument: MemDocument
  PdfStreamedDocument: StreamedDocument

src/podofo/binding.cr

module Podofo
  ...
  class Document
    ...
  end

  class MemDocument < Document
    ...
  end

  class StreamedDocument < Document
    ...
  end
end

ext/podofo_binding.cpp

struct BgInherit_PdfMemDocument : PdfMemDocument {
  using PdfMemDocument::PdfMemDocument;

I've also tried messing around by setting the types manually for each class, but didn't seem to make any difference.

types:
  PdfDocument:
    cpp_type: PoDoFo::PdfDocument
    crystal_type: Document
  # etc

From what I can tell, qt doesn't namespace its classes, so I'm wondering if this is something that was never really implemented since it wasn't needed. I'd be willing to help out, I don't have a ton of experience with code parsing/generation so I'd need a little direction. I also don't have a ton of c++ experience (which is why I'm trying to create crystal bindings 😄 ), I'm mostly a ruby developer but we have some c++ that I have to maintain from time to time.

Also, I have to turn off the sanity_check processor or else everything blows up about invalid aliases and unreachable types for the specified classes.

HertzDevil commented 4 years ago

After that PR you should be able to wrap them directly:

classes:
  PoDoFo::PdfDocument: Document
  PoDoFo::PdfMemDocument: MemDocument
  PoDoFo::PdfStreamedDocument: StreamedDocument

Extra type configuration shouldn't be required and SanityCheck shouldn't break.