Update the webpage (#2549)

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
This commit is contained in:
Zsolt Borbély
2018-10-04 11:04:17 +02:00
committed by Akos Kiss
parent cf87970ef6
commit c846c4ab73
6 changed files with 231 additions and 199 deletions
+10 -23
View File
@@ -17,16 +17,14 @@ This guide is intended to introduce you to JerryScript embedding API through cre
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
int
main (void)
{
const jerry_char_t script[] = "var str = 'Hello, World!';";
size_t script_size = strlen ((const char *) script);
bool ret_value = jerry_run_simple (script, script_size, JERRY_INIT_EMPTY);
bool ret_value = jerry_run_simple (script, sizeof (script) - 1, JERRY_INIT_EMPTY);
return (ret_value ? 0 : 1);
}
@@ -47,7 +45,6 @@ Here we perform the same actions, as `jerry_run_simple`, while splitting into se
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@@ -55,7 +52,6 @@ int
main (void)
{
const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);
/* Initialize engine */
jerry_init (JERRY_INIT_EMPTY);
@@ -65,7 +61,7 @@ main (void)
jerryx_handler_print);
/* Setup Global scope code */
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
if (!jerry_value_is_error (parsed_code))
{
@@ -93,7 +89,6 @@ Our code is more complex now, but it introduces possibilities to interact with J
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@@ -114,7 +109,7 @@ main (void)
/* Evaluate script1 */
eval_ret = jerry_eval (script_1,
strlen ((const char *) script_1),
sizeof (script_1) - 1,
JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
@@ -122,7 +117,7 @@ main (void)
/* Evaluate script2 */
eval_ret = jerry_eval (script_2,
strlen ((const char *) script_2),
sizeof (script_2) - 1,
JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
@@ -142,7 +137,6 @@ This way, we execute two independent script parts in one execution environment.
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@@ -178,7 +172,7 @@ main (void)
/* Now starting script that would output value of just initialized field */
jerry_value_t eval_ret = jerry_eval (script,
strlen ((const char *) script),
sizeof (script) - 1,
JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
@@ -207,7 +201,6 @@ The following example function will output a JavaScript value:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jerryscript.h"
static void
@@ -322,7 +315,7 @@ main (void)
}
/* If the command is "quit", break the loop */
if (!strncmp (cmd, "quit\n", strlen ("quit\n")))
if (!strncmp (cmd, "quit\n", sizeof ("quit\n") - 1))
{
break;
}
@@ -362,7 +355,6 @@ In this example we demonstrate how to use native function and structures in Java
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@@ -427,10 +419,9 @@ main (void)
var str = MyObject.myFunc (); \
print (str); \
";
size_t script_size = strlen ((const char *) script);
/* Evaluate script */
jerry_value_t eval_ret = jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
jerry_release_value (eval_ret);
@@ -455,7 +446,6 @@ Here we create a JS Object with `jerry_eval`, then extend it with a native funct
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@@ -518,7 +508,7 @@ main (void)
/* Evaluate script */
my_js_obj_val = jerry_eval (my_js_object,
strlen ((const char *) my_js_object),
sizeof (my_js_object) - 1,
JERRY_PARSE_NO_OPTS);
/* Create a JS function object and wrap into a jerry value */
@@ -539,10 +529,9 @@ main (void)
MyObject.add2x (5); \
print (MyObject.foo ()); \
";
size_t script_size = strlen ((const char *) script);
/* Evaluate script */
jerry_value_t eval_ret = jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
jerry_release_value (eval_ret);
@@ -569,7 +558,6 @@ A recommended method is using `jerry_port_get_current_time()` or something based
[doctest]: # ()
```c
#include <string.h>
#include <stdlib.h>
#include "jerryscript.h"
#include "jerryscript-port.h"
@@ -583,7 +571,6 @@ main (void)
/* Generate a random number, and print it */
const jerry_char_t script[] = "var a = Math.random (); print(a)";
size_t script_size = strlen ((const char *) script);
/* Initialize the engine */
jerry_init (JERRY_INIT_EMPTY);
@@ -593,7 +580,7 @@ main (void)
jerryx_handler_print);
/* Evaluate the script */
jerry_value_t eval_ret = jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
/* Free the JavaScript value returned by eval */
jerry_release_value (eval_ret);