t22680.nim 800 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. discard """
  2. cmd: "nim cpp $file"
  3. output:'''
  4. cppNZ.x = 123
  5. cppNZInit.x = 123
  6. inheritCpp.x = 123
  7. inheritCppInit.x = 123
  8. inheritCppCtor.x = 123
  9. '''
  10. """
  11. import std/sugar
  12. {.emit:"""/*TYPESECTION*/
  13. struct CppNonZero {
  14. int x = 123;
  15. };
  16. """.}
  17. type
  18. CppNonZero {.importcpp, inheritable.} = object
  19. x: cint
  20. InheritCpp = object of CppNonZero
  21. proc initCppNonZero: CppNonZero =
  22. CppNonZero()
  23. proc initInheritCpp: InheritCpp =
  24. InheritCpp()
  25. proc ctorInheritCpp: InheritCpp {.constructor.} =
  26. discard
  27. proc main =
  28. var cppNZ: CppNonZero
  29. dump cppNZ.x
  30. var cppNZInit = initCppNonZero()
  31. dump cppNZInit.x
  32. var inheritCpp: InheritCpp
  33. dump inheritCpp.x
  34. var inheritCppInit = initInheritCpp()
  35. dump inheritCppInit.x
  36. var inheritCppCtor = ctorInheritCpp()
  37. dump inheritCppCtor.x
  38. main()