|
2 | 2 |
|
3 | 3 | > Self-maintained QuickJS Android Bindings.
|
4 | 4 |
|
5 |
| -## Download |
| 5 | +## Usage |
6 | 6 |
|
7 |
| -1. Download latest `.aar` from [release](https://github.com/shiqimei/quickjs-android/releases) page. |
| 7 | +1. Download the latest `.aar` archive from [release](https://github.com/shiqimei/quickjs-android/releases) page; |
8 | 8 | 2. In Android Studio: `File > New > New Module > Import .JAR/.AAR Package`, locate `.aar`, click `Finish`.
|
9 | 9 |
|
10 |
| -## Usage |
11 |
| - |
12 |
| -### Evaluate Javascript Scripts |
13 |
| - |
14 |
| -```Java |
15 |
| -QuickJS quickJS = new QuickJS.Builder().build(); |
16 |
| -try (JSRuntime runtime = quickJS.createJSRuntime()) { |
17 |
| - try (JSContext context = runtime.createJSContext()) { |
18 |
| - String script1 = "" + |
19 |
| - "function fibonacci(n) {" + |
20 |
| - " if (n == 0 || n == 1) return n;" + |
21 |
| - " return fibonacci(n - 1) + fibonacci(n - 2);" + |
22 |
| - "}"; |
23 |
| - // Evaluate a script without return value |
24 |
| - context.evaluate(script1, "fibonacci.js"); |
25 |
| - |
26 |
| - String script2 = "fibonacci(10);"; |
27 |
| - // Evaluate a script with return value |
28 |
| - int result = context.evaluate(script2, "fibonacci.js", int.class); |
29 |
| - assertEquals(55, result); |
| 10 | + ```Java |
| 11 | + QuickJS quickJS = new QuickJS.Builder().build(); |
| 12 | + try (JSRuntime runtime = quickJS.createJSRuntime()) { |
| 13 | + try (JSContext context = runtime.createJSContext()) { |
| 14 | + String script1 = "" + |
| 15 | + "function fibonacci(n) {" + |
| 16 | + " if (n == 0 || n == 1) return n;" + |
| 17 | + " return fibonacci(n - 1) + fibonacci(n - 2);" + |
| 18 | + "}"; |
| 19 | + // Evaluate a script without return value |
| 20 | + context.evaluate(script1, "fibonacci.js"); |
| 21 | + |
| 22 | + String script2 = "fibonacci(10);"; |
| 23 | + // Evaluate a script with return value |
| 24 | + int result = context.evaluate(script2, "fibonacci.js", int.class); |
| 25 | + assertEquals(55, result); |
| 26 | + } |
30 | 27 | }
|
31 |
| -} |
32 |
| -``` |
| 28 | + ``` |
33 | 29 |
|
34 |
| -See [Usages](./Usages.md) for advanced usages. |
| 30 | + See [Usages.md](./Usages.md) for advanced usages. |
35 | 31 |
|
36 | 32 | ## Develop
|
37 | 33 |
|
|
0 commit comments