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 {
22 long a ;
33 int b ;
44 long long c ;
55};
6+
7+ union values * getValues ();
Original file line number Diff line number Diff line change @@ -6,14 +6,15 @@ import scala.scalanative.native._
66@ native.link(" bindgentests" )
77@ native.extern
88object 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
1011}
1112
1213import Union ._
1314
1415object UnionHelpers {
1516
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 {
1718 def a : native.Ptr [native.CLong ] = p.cast[native.Ptr [native.CLong ]]
1819 def a_= (value : native.CLong ): Unit = ! p.cast[native.Ptr [native.CLong ]] = value
1920 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