panama tools and demos
[panamaz] / test-api / api / test / TestAPI.java
1
2 package api.test;
3
4 import java.foreign.*;
5 import java.foreign.memory.*;
6 import java.foreign.annotations.*;
7 import java.util.function.IntFunction;
8
9 import api.*;
10
11 public class TestAPI {
12         public static void main(String[] args) {
13                 APILib lib = APILib.bind;
14                 LayoutType<Data> dataLayout = LayoutType.ofStruct(Data.class);
15
16                 try (Scope s = Libraries.libraryScope(lib).fork()) {
17                         Pointer<Data> a = s.allocate(dataLayout);
18                         Pointer<Data> b = s.allocate(dataLayout);
19                         Callback<Call__I> cb = s.allocateCallback(Call__I.class,
20                                 () -> {
21                                         return 56;
22                                 });
23
24                         Data ad = a.get();
25                         Data bd = b.get();
26
27                         ad.setNext(b);
28                         ad.setA(1);
29                         ad.setB(2);
30                         ad.setC((byte)3);
31                         ad.setD((byte)4);
32
33                         bd.setA(5);
34                         bd.setB(6);
35                         bd.setC((byte)255);
36                         bd.setD((byte)255);
37
38                         bd.setTestA(cb);
39
40                         System.out.println("from a\n");
41                         lib.print_data(a);
42                         System.out.println("\bfrom b\n");
43                         lib.print_data(b);
44                 }
45         }
46 }