Hello. How to check type inside macro?
    
    
    import macros
    type
      T1 = object
        s : string
    
    proc checkTypeProc( t : typedesc )=
      if t is T1:
        echo "proc: is T1"
      else:
        echo "proc: not T1"
    
    macro checkTypeMacro(t:static[typedesc]):untyped=
      if t is T1:
        result = quote do: echo "macro: is T1"
      else:
        result = quote do: echo "macro: not T1"
    
    if isMainModule:
      checkTypeProc(T1)
      checkTypeMacro(T1)
    
    # Output:
    # proc: is T1
    # macro: not T1
    
    
    Run

Reply via email to