File: tvectorseq.nim

package info (click to toggle)
nim 1.4.6%2Breally1.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 936,800 kB
  • sloc: sh: 17,201; ansic: 4,767; makefile: 856; python: 407; sql: 298; asm: 141; xml: 13
file content (38 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
discard """
  targets: "cpp"
  output: '''(x: 1.0)
(x: 0.0)'''
  disabled: "true"
"""

# This cannot work yet because we omit type information for importcpp'ed types.
# Fixing this is not hard, but also requires fixing Urhonimo.

# bug #2536

{.emit: """/*TYPESECTION*/
struct Vector3 {
public:
  Vector3(): x(5) {}
  Vector3(float x_): x(x_) {}
  float x;
};
""".}

type Vector3 {.importcpp: "Vector3", nodecl} = object
  x: cfloat

proc constructVector3(a: cfloat): Vector3 {.importcpp: "Vector3(@)", nodecl}

# hack around another codegen issue: Generics are attached to where they came
# from:
proc `$!`(v:  seq[Vector3]): string = "(x: " & $v[0].x & ")"

proc vec3List*(): seq[Vector3] =
  let s = @[constructVector3(cfloat(1))]
  echo($!s)
  result = s
  echo($!result)

let f = vec3List()
#echo($!f)