@@ -11,7 +11,7 @@ This guide is intended to introduce you to JerryScript embedding API through cre
11
11
int
12
12
main (int argc, char * argv[ ] )
13
13
{
14
- const jerry_char_t script[ ] = "print ( 'Hello, World!') ;";
14
+ const jerry_char_t script[ ] = "var str = 'Hello, World!';";
15
15
size_t script_size = strlen ((const char * ) script);
16
16
17
17
bool ret_value = jerry_run_simple (script, script_size, JERRY_INIT_EMPTY);
@@ -20,11 +20,7 @@ main (int argc, char *argv[])
20
20
}
21
21
```
22
22
23
- The application will generate the following output:
24
-
25
- ```bash
26
- Hello, World!
27
- ```
23
+ The application will return with zero exit code.
28
24
29
25
## Step 2. Split engine initialization and script execution
30
26
@@ -39,6 +35,7 @@ Here we perform the same actions, as `jerry_run_simple`, while splitting into se
39
35
```c
40
36
#include <string.h>
41
37
#include "jerryscript.h"
38
+ #include "jerryscript-ext/handler.h"
42
39
43
40
int
44
41
main (int argc, char *argv[])
@@ -49,6 +46,10 @@ main (int argc, char *argv[])
49
46
/* Initialize engine */
50
47
jerry_init (JERRY_INIT_EMPTY);
51
48
49
+ /* Register 'print' function from the extensions */
50
+ jerryx_handler_register_global ((const jerry_char_t *) "print",
51
+ jerryx_handler_print);
52
+
52
53
/* Setup Global scope code */
53
54
jerry_value_t parsed_code = jerry_parse (script, script_size, false);
54
55
@@ -78,6 +79,7 @@ Our code is more complex now, but it introduces possibilities to interact with J
78
79
``` c
79
80
#include < string.h>
80
81
#include " jerryscript.h"
82
+ #include " jerryscript-ext/handler.h"
81
83
82
84
int
83
85
main (int argc, char * argv[ ] )
@@ -88,6 +90,10 @@ main (int argc, char *argv[])
88
90
/* Initialize engine * /
89
91
jerry_init (JERRY_INIT_EMPTY);
90
92
93
+ /* Register 'print' function from the extensions * /
94
+ jerryx_handler_register_global ((const jerry_char_t * ) "print",
95
+ jerryx_handler_print);
96
+
91
97
jerry_value_t eval_ret;
92
98
93
99
/* Evaluate script1 * /
@@ -120,6 +126,7 @@ This way, we execute two independent script parts in one execution environment.
120
126
```c
121
127
#include <string.h>
122
128
#include "jerryscript.h"
129
+ #include "jerryscript-ext/handler.h"
123
130
124
131
int
125
132
main (int argc, char *argv[]) {
@@ -129,6 +136,10 @@ main (int argc, char *argv[]) {
129
136
/* Initializing JavaScript environment */
130
137
jerry_init (JERRY_INIT_EMPTY);
131
138
139
+ /* Register 'print' function from the extensions */
140
+ jerryx_handler_register_global ((const jerry_char_t *) "print",
141
+ jerryx_handler_print);
142
+
132
143
/* Getting pointer to the Global object */
133
144
jerry_value_t global_object = jerry_get_global_object ();
134
145
@@ -176,7 +187,6 @@ The following example function will output a JavaScript value:
176
187
#include < stdio.h>
177
188
#include < stdlib.h>
178
189
#include < string.h>
179
-
180
190
#include " jerryscript.h"
181
191
182
192
static void
@@ -246,8 +256,8 @@ Shell operation can be described with the following loop:
246
256
#include <stdio.h>
247
257
#include <stdlib.h>
248
258
#include <string.h>
249
-
250
259
#include "jerryscript.h"
260
+ #include "jerryscript-ext/handler.h"
251
261
252
262
static void print_value (const jerry_value_t);
253
263
@@ -259,6 +269,10 @@ main (int argc, char *argv[])
259
269
/* Initialize engine */
260
270
jerry_init (JERRY_INIT_EMPTY);
261
271
272
+ /* Register 'print' function from the extensions */
273
+ jerryx_handler_register_global ((const jerry_char_t *) "print",
274
+ jerryx_handler_print);
275
+
262
276
while (!is_done)
263
277
{
264
278
char cmd[256] = {};
@@ -325,6 +339,7 @@ In this example we demonstrate how to use native function and structures in Java
325
339
``` c
326
340
#include < string.h>
327
341
#include " jerryscript.h"
342
+ #include " jerryscript-ext/handler.h"
328
343
329
344
struct my_struct
330
345
{
@@ -349,6 +364,10 @@ main (int argc, char *argv[])
349
364
/* Initialize engine * /
350
365
jerry_init (JERRY_INIT_EMPTY);
351
366
367
+ /* Register 'print' function from the extensions * /
368
+ jerryx_handler_register_global ((const jerry_char_t * ) "print",
369
+ jerryx_handler_print);
370
+
352
371
/* Do something with the native object * /
353
372
my_struct.msg = "Hello World";
354
373
@@ -411,6 +430,7 @@ Here we create a JS Object with `jerry_eval`, then extend it with a native funct
411
430
``` c
412
431
#include < string.h>
413
432
#include " jerryscript.h"
433
+ #include " jerryscript-ext/handler.h"
414
434
415
435
/* *
416
436
* Add param to 'this.x'
@@ -451,6 +471,10 @@ main (int argc, char *argv[])
451
471
/* Initialize engine * /
452
472
jerry_init (JERRY_INIT_EMPTY);
453
473
474
+ /* Register 'print' function from the extensions * /
475
+ jerryx_handler_register_global ((const jerry_char_t * ) "print",
476
+ jerryx_handler_print);
477
+
454
478
/* Create a JS object * /
455
479
const jerry_char_t my_js_object[ ] = " \
456
480
MyObject = \
0 commit comments