Added untested Scala binding
This commit is contained in:
18
examples/bindings/scala/Makefile
Normal file
18
examples/bindings/scala/Makefile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
OSTYPE=$(shell uname -s | tr '[A-Z]' '[a-z]')
|
||||||
|
BUILD=build/$(OSTYPE)
|
||||||
|
|
||||||
|
ifeq ($(OSTYPE),darwin)
|
||||||
|
SHARED_LIB=libzt.dylib
|
||||||
|
endif
|
||||||
|
ifeq ($(OSTYPE),linux)
|
||||||
|
SHARED_LIB=libzt.so
|
||||||
|
endif
|
||||||
|
|
||||||
|
example_scala_app:
|
||||||
|
scalac *.scala
|
||||||
|
|
||||||
|
copy_dynamic_lib:
|
||||||
|
cp ../../../$(BUILD)/$(SHARED_LIB) .
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-find . -type f \( -name '*.class' \) -delete
|
||||||
14
examples/bindings/scala/README.md
Normal file
14
examples/bindings/scala/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
## ZeroTier with Scala via JNI
|
||||||
|
***
|
||||||
|
|
||||||
|
To get this example project to work, do the following:
|
||||||
|
|
||||||
|
- From libzt main directory, build shared library: `make shared_jni_lib`
|
||||||
|
- Copy the resultant dynamic library (`*.so` or `*.dylib`) from `build/` to this current directory
|
||||||
|
- Change to this directory and `make example_scala_app`
|
||||||
|
- Run: `scala -cp "." ExampleApp`
|
||||||
|
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
Upon execution, it will load the libzt dynamic library via the `loadLibrary` method and begin generating an identity.
|
||||||
13
examples/bindings/scala/libzt.scala
Normal file
13
examples/bindings/scala/libzt.scala
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
class ZeroTier {
|
||||||
|
@native def ztjni_socket(socket_family: Int, socket_type: Int, protocol: Int): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
object ZeroTier extends App {
|
||||||
|
|
||||||
|
System.loadLibrary("zt")
|
||||||
|
|
||||||
|
val libzt = new ZeroTier
|
||||||
|
val fd = libzt.ztjni_socket(2, 1, 0)
|
||||||
|
println(s"zts_socket(): $fd")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user