There is limited support for Java integration. There are three different ways to communicate with Java:
IBinding
interfaceThe interpreter has to know where to find the classes before it can load them. You can add include directories and Jar files by using the -I
option:
java -jar sikkel.jar script.sik -I bin
java -jar sikkel.jar script.sik -I library.jar
Java
package de.slashbinbash.sikkel;
public class TestClass {
public static int testA(int a, int b) {
return a + b;
}
public static String testB() {
return "test";
}
}
Import all methods with class namespace import
(require system)
(import de.slashbinbash.sikkel.TestClass)
(TestClass.testA 10 15)
=> 25
(TestClass.testB)
=> "test"
Import all methods with import-static
(require system)
(import-static de.slashbinbash.sikkel.TestClass.*)
(testA 42 8)
=> 50
(testB)
=> "test"
Import single method with import-static
(require system)
(import-static de.slashbinbash.sikkel.TestClass.testA)
(testA 8 12)
=> 20
(testB)
=> error: undefined
Constraints:
public static
Java methodsboolean
, int
, and String
Load classes that implement the IBinding
interface:
Java
package de.slashbinbash.sikkel;
public class Test implements IBinding {
@Override
public Atom eval(Interpreter terp, NList list) {
return new NInt(42);
}
}
Sikkel
(require system)
(define test (import-ibinding de.slashbinbash.sikkel.Test))
(test)
=> 42