tvectorseq.nim 807 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. discard """
  2. targets: "cpp"
  3. output: '''(x: 1.0)
  4. (x: 0.0)'''
  5. disabled: "true"
  6. """
  7. # This cannot work yet because we omit type information for importcpp'ed types.
  8. # Fixing this is not hard, but also requires fixing Urhonimo.
  9. # bug #2536
  10. {.emit: """/*TYPESECTION*/
  11. struct Vector3 {
  12. public:
  13. Vector3(): x(5) {}
  14. Vector3(float x_): x(x_) {}
  15. float x;
  16. };
  17. """.}
  18. type Vector3 {.importcpp: "Vector3", nodecl} = object
  19. x: cfloat
  20. proc constructVector3(a: cfloat): Vector3 {.importcpp: "Vector3(@)", nodecl}
  21. # hack around another codegen issue: Generics are attached to where they came
  22. # from:
  23. proc `$!`(v: seq[Vector3]): string = "(x: " & $v[0].x & ")"
  24. proc vec3List*(): seq[Vector3] =
  25. let s = @[constructVector3(cfloat(1))]
  26. echo($!s)
  27. result = s
  28. echo($!result)
  29. let f = vec3List()
  30. #echo($!f)