I have this macro, which works fine.
    
    
    macro gDefineTypeExtended*(tn, t, tp, f, c: static[string]): stmt =
      var
        cc = indent("\n" & c, 4)
        s = """
    
    proc $2Init(self: $1) {.cdecl.}
    proc $2ClassInit(klass: $1Class) {.cdecl.}
    var $2ParentClass: Gpointer = nil
    var $1PrivateOffset: cint
    proc $2ClassInternInit(klass: Gpointer) {.cdecl.} =
      $2ParentClass = typeClassPeekParent(klass)
      if $1PrivateOffset != 0:
        typeClassAdjustPrivateOffset(klass, $1PrivateOffset)
      
      $2ClassInit(cast[$1Class](klass))
    
    proc $2GetInstancePrivate(self: $1): $1Private {.cdecl.} =
      return cast[$1Private](gStructMemberP(self, $1PrivateOffset))
    
    proc $2GetType*(): GType {.cdecl.} =
      var gDefineTypeIdVolatile {.global.}: Gsize = 0
      if onceInitEnter(addr(gDefineTypeIdVolatile)):
        var gDefineTypeId: GType = registerStaticSimple($3,
                                          internStaticString("$1"),
                                          sizeof($1ClassObj).cuint,
                                          
cast[GClassInitFunc]($2ClassInternInit),
                                          sizeof($1Obj).cuint,
                                          cast[GInstanceInitFunc]($2Init),
                                          cast[GTypeFlags]($4))
        $5
        onceInitLeave(addr(gDefineTypeIdVolatile), gDefineTypeId)
      return gDefineTypeIdVolatile
    
    """ % [tn, t, tp, f, cc]
      #echo s
      result = parseStmt(s)
    

But it would be nice if proc $2GetInstancePrivate is not generated when last 
macro parameter c is "". May it be possible to put a when statement in this 
macro to opionally suppress generation of proc $2GetInstancePrivate? (Of course 
I can make a copy of this macro with another name and without that proc)

Reply via email to