Advertisement
Guest User

nim-typeImportC-template

a guest
Apr 6th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.61 KB | None | 0 0
  1. template typeImportC*(typeName: untyped, importC: string, header: string, baseType: typed, decl: untyped): typed =
  2.   when defined(useHeaderImportC):
  3.     type
  4.       typeName {.importC: importC, header: header.} = baseType
  5.         decl
  6.   else:
  7.     type
  8.       typeName = baseType
  9.         decl
  10.  
  11. typeImportC(`NimType *`, "NativeType", "imported.h", object):
  12.   f1*: uint
  13.   f2*: uint
  14.  
  15. # Should Produce
  16. when defined(useHeaderImportC):
  17.   type
  18.     NimType* {.importC: "NativeType", header: "imported.h".} = object
  19.       f1*: cint
  20.       f2*: cint
  21. else:
  22.   type
  23.     NimType* = object
  24.       f1*: cint
  25.       f2*: cint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement