timportc.nim 416 B

12345678910111213141516171819202122232425
  1. discard """
  2. targets: "c cpp js"
  3. """
  4. when defined(c) or defined(cpp):
  5. {.emit:"""
  6. const int TEST1 = 123;
  7. #define TEST2 321
  8. """.}
  9. when defined(js):
  10. {.emit:"""
  11. const TEST1 = 123;
  12. const TEST2 = 321; // JS doesn't have macros, so we just duplicate
  13. """.}
  14. let
  15. TEST0 = 1
  16. TEST1 {.importc, nodecl.}: cint
  17. TEST2 {.importc, nodecl.}: cint
  18. doAssert TEST0 == 1
  19. doAssert TEST1 == 123
  20. doAssert TEST2 == 321