Skip to content

Commit 823381a

Browse files
author
Mihail Slavchev
committed
update binding genator home page
1 parent 42d0196 commit 823381a

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

binding-generator/README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
11
# android-binding-generator
2-
Contains the source of the binding generator tool for the NativeScript's Android Runtime.
2+
3+
This project is used in the [NativeScript runtime for Android](https://github.com/NativeScript/android-runtime) to generate Java subclasses at runtime. Supppose you have the following Java class
4+
5+
```Java
6+
package com.example;
7+
8+
public class MyClass {
9+
public int add(int x, int y) {
10+
return x + y;
11+
}
12+
}
13+
```
14+
15+
In NativeScript, you can inherit from `MyClass` using the following syntax:
16+
17+
```JavaScript
18+
var MyNewClass = com.example.MyClass.extend({
19+
add: function(x, y) {
20+
return x * y;
21+
}
22+
})
23+
24+
var obj = new MyNewClass();
25+
```
26+
27+
Using `extend` function will create a new Java class that looks roughly as follows
28+
```Java
29+
package <some auto-generated package name>;
30+
31+
public <some auto-generated class name> extends com.example.MyClass {
32+
public int add(int x, int y) {
33+
java.lang.Object[] params = new Object[2];
34+
params[0] = x;
35+
params[1] = y;
36+
return (int)com.tns.Platform.callJSMethod(this, "add", int.class, params);
37+
}
38+
}
39+
```
40+
The binding generator uses [ASMDEX library](http://asm.ow2.org/asmdex-index.html) to create the class above and to produce the corresponding `*.dex` file.

0 commit comments

Comments
 (0)