-
Notifications
You must be signed in to change notification settings - Fork 77
BridJAndScala
[TOC]
BridJ was designed with JNAerator in mind, so that you never have to translate any C / C++ / ObjectiveC header by hand.
JNAerator creates Java sources or classes, that can then be used seamlessly from Scala.
However, BridJ has some Scala-specific features in its core classes, and JNAerator has Scala-specific generation modes.
This page details these Scala-oriented features.
BridJ's pointer class was designed to behave like a list, so provided you import scala.collection.JavaConversions._
you'll be able to iterate over its pointed elements.
It also implements apply and update, so indexed access can be made with the natural Scala syntax :
val value = pointer(index)
pointer(index) = value
C code that demonstrates multi-dimensional arrays declarations and usage :
```
float array1d[100];
float array2d[100][200];
float array3d[100][200][300];
float v1 = array1d[10]; float v2 = array2d[10][20]; float v3 = array3d[10][20][30]; array3d[10][20][30] = v1 + v2 + v3;
import org.bridj.Pointer._ val array1d = allocateFloats(100) val array2d = allocateFloats(100, 200) val array3d = allocateFloats(100, 200, 300) val v1 = array1d(10) val v2 = array2d(10)(20) val v3 = array3d(10)(20)(30) array3d(10)(20)(30) = v1 + v2 + v3
import org.bridj.Pointer; import static org.bridj.Pointer.*; ... Pointer array1d = allocateFloats(100); Pointer<Pointer> array2d = allocateFloats(100, 200); Pointer<Pointer<Pointer>> array3d = allocateFloats(100, 200, 300); float v1 = array1d.get(10); float v2 = array2d.get(10).get(20); float v3 = array3d.get(10).get(20).get(30); array3d.get(10).get(20).set(30, v1 + v2 + v3);
typedef struct S { int a; double d; } S; S s; s.a = 10; s.d = 10.0;
// Using autogenerated S structure code val s = new S.a(10).d(10.0)
val s = new S s.a = 10 s.d = 10.0
S s = new S().a(10).d(10.0)
|