Mercurial > pub > dyncall > bindings
annotate java/jdc/examples/UnixMathExample.java @ 56:16151547265e
made callback example python 2 compatible, and added some randomness to numbers to sort
author | Tassilo Philipp |
---|---|
date | Tue, 02 Feb 2021 21:07:41 +0100 |
parents | 4ee8d6aa7721 |
children |
rev | line source |
---|---|
21 | 1 import org.dyncall.DC; |
2 | |
3 class UnixMathExample | |
4 { | |
5 public static void main(String args[]) | |
6 { | |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
7 long lib = DC.loadLibrary("/usr/lib/libm.so"); |
21 | 8 System.out.format("libm.so handle: %x\n", lib); |
9 | |
10 long f0 = DC.find(lib, "sqrtf"); | |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
11 System.out.format("found sqrtf at: %x\n", f0); |
21 | 12 |
13 long f1 = DC.find(lib, "pow"); | |
14 System.out.format("found pow at: %x\n", f1); | |
15 | |
16 long vm = DC.newCallVM(4096); | |
17 DC.argFloat(vm, 36.f); | |
18 float r0 = DC.callFloat(vm, f0); | |
19 System.out.format("sqrtf(36.f) = %f\n", r0); | |
20 | |
21 DC.reset(vm); | |
22 DC.argDouble(vm, 2.); | |
23 DC.argDouble(vm, 10.); | |
24 double r1 = DC.callDouble(vm, f1); | |
25 System.out.format("pow(2., 10.) = %f\n", r1); | |
22
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
26 |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
27 // Done, cleanup. |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
28 DC.freeCallVM(vm); |
4ee8d6aa7721
- java binding cleanup, exposed free functions (not very oo, this entire binding)
cslag
parents:
21
diff
changeset
|
29 DC.freeLibrary(lib); |
21 | 30 } |
31 } | |
32 |