Skip to content

Macros allowing generating compact and readable wrappers to C++ classes for Nim programming language

License

Notifications You must be signed in to change notification settings

xomachine/wraptool-cpp2nim

Repository files navigation

wraptool-cpp2nim

Macros allowing generating compact and readable wrappers to C++ classes for Nim programming language

Work in progress.

Macros allow you create C++ code wrapper in following style:

wrapheader "<opencv2/core.hpp>":
  namespace "cv":
    class "Rect_" as Rect[T]:
      proc Rect(x, y, w, h: T)
      proc area*(): T
      
    class Mat:
      proc Mat(rows, cols, t: cint)
      proc clone(): Mat

The code above will be expanded to:

type
    Rect* {.importcpp: "cv::Rect_<\'0>", header: "<opencv2/core.hpp>".}[T] = object
    Mat* {.importcpp: "cv::Mat", header: "<opencv2/core.hpp>".} = object
proc newRect*[T](): Rect[T] {.importcpp: "cv::Rect(@)",
                           header: "<opencv2/core.hpp>", constructor.}
proc newRect*[T](x, y, w, h: T): Rect[T] {.importcpp: "cv::Rect(@)",
                                    header: "<opencv2/core.hpp>", constructor.}
proc area*[T](this: Rect[T]): T {.importcpp: "#.cv::Rect_<\'0>::area(@)",
                              header: "<opencv2/core.hpp>".}
proc newMat*(): Mat {.importcpp: "cv::Mat(@)", header: "<opencv2/core.hpp>",
                   constructor.}
proc newMat*(rows, cols, t: cint): Mat {.importcpp: "cv::Mat(@)",
                                   header: "<opencv2/core.hpp>", constructor.}
proc clone*(this: Mat): Mat {.importcpp: "#.cv::Mat::clone(@)",
                          header: "<opencv2/core.hpp>".} 

for header like following:

namespace cv {
  template<typename _Tp> class Rect_
  {
  public:
    Rect_();
    Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
    _Tp area() const;
  }
  
  class Mat
  {
  public:
    Mat();
    Mat(int rows, int cols);
    Mat clone();
}

Documentation generated automaticaly if following command executed:

$ nim doc wraptool.nim

About

Macros allowing generating compact and readable wrappers to C++ classes for Nim programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages