pragma pragma

The pragma pragma can be used to declare user defined pragmas. This is useful because Nim’s templates and macros do not affect pragmas. User defined pragmas are in a different module-wide scope than all other symbols. They cannot be imported from a module.

Example:

  1. when appType == "lib":
  2. {.pragma: rtl, exportc, dynlib, cdecl.}
  3. else:
  4. {.pragma: rtl, importc, dynlib: "client.dll", cdecl.}
  5. proc p*(a, b: int): int {.rtl.} =
  6. result = a+b

In the example a new pragma named rtl is introduced that either imports a symbol from a dynamic library or exports the symbol for dynamic library generation.