@@ -4,47 +4,52 @@ Consider following header file:
44
55@@snip [ vector.h] (../test/resources/vector.h)
66
7- Bindgen will generate type aliases for the structs, binding for function ` add `
8- and helper functions that make usage of structs easier.
7+ Bindgen will output
8+ * type aliases for the structs
9+ * binding for function ` cosine `
10+ * helper functions that make usage of structs easier
911
1012@@snip [ vector.h] (../test/scala/org/example/vector.scala)
1113
12- Let's write code that creates two vectors, adds them and prints resulting
13- vector.
14+ Let's write code that creates two line segments and prints angel between them.
1415
15- First we need to create points for vectors . We will use ` native.Zone ` to
16+ First we need to create points. We will use ` native.Zone ` to
1617allocate struct (more information on memory management can be found
1718here: [ Scala Native memory management] ).
1819
19- Helper object ` mylibHelpers ` contains function for struct allocation.
20- To import it use ` import mylibHelpers ._ `
20+ Generated bindings contain helper functions that make struct allocation easier .
21+ To import them use ` import org.example.vector ._ `
2122
22- Let's create points for first vector :
23+ Let's create two points and the first line segment :
2324
2425@@snip [ step-1] (../test/scala/org/scalanative/bindgen/docs/VectorSpec.scala) { #step-1 }
2526
26- Now we want to set fields of created points. Scala Native provides access
27- to fields by using ` _N ` methods where ` N ` is index of a field
28- (see [ Scala Native memory layout types] ).
27+ There is no need to create points manually, just call ` struct_lineSegment `
28+ constructor and set point coordinates using fields setters.
2929
30- Bindgen generates implicit helper classes that wrap calls to ` _N ` in functions
31- with meaningful names. We already imported helper class, so we can use the
32- functions:
30+ Scala Native allows us to access a field by using ` _N ` method where ` N ` is index of a field
31+ (see [ Scala Native memory layout types] ) but it is not convenient because we have to
32+ match indices with fields names.
33+
34+ Bindgen provides implicit helper classes that wrap calls to ` _N ` in functions
35+ with meaningful names. To import these classes add ` import org.example.vector.implicits._ `
36+ to your code:
3337
3438@@snip [ step-2] (../test/scala/org/scalanative/bindgen/docs/VectorSpec.scala) { #step-2 }
3539
36- Lets create first vector. Note that ` struct_vector ` contains
37- fields of type ` struct_point ` but setters accept variables of type
38- ` native.Ptr[struct_point] ` . It helps to avoid Scala Native limitation that
39- does not allow passing structs and arrays by value
40- (see @github [ scala-native/scala-native #555 ] ( scala-native/scala-native#555 ) ).
40+ @@@ note
41+
42+ Note that ` struct_lineSegment ` contains fields of value type ` struct_point `
43+ but setters accept variables of type ` native.Ptr[struct_point] ` .
44+ It helps to avoid Scala Native limitation that does not allow passing structs
45+ and arrays by value (see @github [ scala-native/scala-native #555 ] ( scala-native/scala-native#555 ) ).
46+
47+ @@@
4148
42- @ @ snip [ step-3 ] (../test/scala/org/scalanative/bindgen/docs/VectorSpec.scala) { #step-3 }
49+ Now we can calculate angel between line segments:
4350
44- Repeat these steps to create second vector. Once both vectors are created we can
45- call ` add ` function and print the result:
51+ @@snip [ step-3] (../test/scala/org/scalanative/bindgen/docs/VectorSpec.scala) { #step-2 }
4652
47- @@snip [ step-4] (../test/scala/org/scalanative/bindgen/docs/VectorSpec.scala) { #step-4 }
4853
4954 [ Scala Native memory management ] : http://www.scala-native.org/en/latest/user/interop.html#memory-management
5055 [ Scala Native memory layout types ] : http://www.scala-native.org/en/latest/user/interop.html#memory-layout-types
0 commit comments