public class TeaVMEntryPoint extends Object
An entry point to a generated VM that is used to enter the VM from a JavaScript code.
The entry point is added by TeaVM.entryPoint(String, MethodReference).
Use withValue(int, String) to specify actual types that are passed to the entry point.
In the simple case of static method without arguments you won't deal with this class. But sometimes you have to. Consider the following example:
static void entryPoint(Map<Object, Object> map) {
for (Map.Entry<Object, Object> entry : map.entrySet()) {
System.out.println(entry.getKey() + " => " + entry.getValue());
}
}
Now you want to call this method from JavaScript, and you pass a HashMap to this method.
Let's see how you achieve it:
vm.exportType("JavaHashMap", "java.util.HashMap");
vm.entryPoint("initJavaHashMap", new MethodReference("java.util.HashMap",
"<init>", ValueType.VOID));
vm.entryPoint("putValueIntoJavaMap", new MethodReference(
"java.util.Map", "put",
ValueType.object("java.lang.Object"), ValueType.object("java.lang.Object"),
ValueType.object("java.lang.Object")))
.withValue(0, "java.util.HashMap")
.withValue(1, "java.lang.String")
.withValue(2, "java.lang.String");
vm.entryPoint("entryPoint", new MethodReference(
"fully.qualified.ClassName", "entryPoint",
ValueType.object("java.util.Map"), ValueType.VOID))
.withValue(1, "java.util.HashMap")
And in JavaScript you would do the following:
var map = new JavaHashMap();
initJavaHashMap(map);
putValueIntoJavaMap(map, $rt_str("foo"), $rt_str("bar"));
entryPoint(map);
If you didn't call .withValue(1, "java.util.HashMap"), TeaVM could not know,
what implementation of entrySet method to include.
| Modifier and Type | Method and Description |
|---|---|
TeaVMEntryPoint |
async() |
TeaVMEntryPoint |
withArrayValue(int argument,
String type) |
TeaVMEntryPoint |
withValue(int argument,
String type) |
public TeaVMEntryPoint withValue(int argument, String type)
public TeaVMEntryPoint withArrayValue(int argument, String type)
public TeaVMEntryPoint async()
Copyright © 2015. All rights reserved.