File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed
src/test/scala/org/scalanative/bindgen/samples Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change
1
+ #include "Union.h"
2
+ #include <stdlib.h>
3
+
4
+ union values * getValues () {
5
+ union values * myValues = malloc (sizeof (union values ));
6
+ myValues -> a = 10 ;
7
+ return myValues ;
8
+ }
Original file line number Diff line number Diff line change 1
- union point {
1
+ union values {
2
2
long a ;
3
3
int b ;
4
4
long long c ;
5
5
};
6
+
7
+ union values * getValues ();
Original file line number Diff line number Diff line change @@ -6,14 +6,15 @@ import scala.scalanative.native._
6
6
@ native.link(" bindgentests" )
7
7
@ native.extern
8
8
object Union {
9
- type union_point = native.CArray [Byte , native.Nat .Digit [native.Nat ._6, native.Nat ._4]]
9
+ type union_values = native.CArray [Byte , native.Nat .Digit [native.Nat ._6, native.Nat ._4]]
10
+ def getValues (): native.Ptr [union_values] = native.extern
10
11
}
11
12
12
13
import Union ._
13
14
14
15
object UnionHelpers {
15
16
16
- implicit class union_point_pos (val p : native.Ptr [union_point ]) extends AnyVal {
17
+ implicit class union_values_pos (val p : native.Ptr [union_values ]) extends AnyVal {
17
18
def a : native.Ptr [native.CLong ] = p.cast[native.Ptr [native.CLong ]]
18
19
def a_= (value : native.CLong ): Unit = ! p.cast[native.Ptr [native.CLong ]] = value
19
20
def b : native.Ptr [native.CInt ] = p.cast[native.Ptr [native.CInt ]]
Original file line number Diff line number Diff line change
1
+ package org .scalanative .bindgen .samples
2
+
3
+ import utest ._
4
+ import scala .scalanative .native ._
5
+ import org .scalanative .bindgen .samples .UnionHelpers ._
6
+
7
+ object UnionTests extends TestSuite {
8
+ val tests = Tests {
9
+ ' getValues - {
10
+ val point = Union .getValues()
11
+ assert(point.a == 10 )
12
+ }
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments