n0bra1n3r/cinterop

Simplify DSL further

Opened this issue · 0 comments

Idea

cinclude "header1.hpp"
cinclude "header2.hpp"

cnamespace Namespace

type Type1*[T] {.ccls.} = object
  proc staticMethod1*(Self)

  field1*: int

  proc method1*(self: var)

  type NestedType1* = object
    proc method2*(self)

type ENUM_1* {.cenu.} = enum
  a
  b
  c

proc function1*() {.cfun.}

expands to:

var cinterop_includes_private {.compileTime.} = "#include \"header1.hpp\"\n#include \"header2.hpp\"\n"
var cinterop_namespace_private {.compileTime.} = "Namespace"

type
  Type1*[T] {.importcpp:cinterop_namespace_private&"::$1" header:cinterop_includes_private.} = object of CClass
    field1*: int
  Type1Ext`somepostfix = cinterop_class_ext_private:
    proc staticMethod1*(Self) {.importcpp:"'1::$1(@)" header:cinterop_includes_private.}
    proc method1*(self: var Self) {.importcpp:"#.$1(@)" header:cinterop_includes_private.}

    type
      NestedType1`somepostfix {.importcpp:cinterop_namespace_private&"::Type1::$1" header:cinterop_includes_private.} = object
      NestedType1Ext`somepostfix = cinterop_class_ext_private:
        proc method2*(self) {.importcpp:"#.$1(@)" header:cinterop_includes_private.}

    template NestedType1*[T](Parent: Type1[T]): type = NestedType1`somepostfix

type 
  ENUM_1* = object of CEnum
    val: ENUM_1Val`somepostfix
  ENUM_1`somepostfix {.importcpp:cinterop_namespace_private&"::$1" header:cinterop_includes_private.} = enum
    a
    b
    c

proc function1*() {.importcpp:cinterop_namespace_private&"::$1(@)" header:cinterop_includes_private.}