Update the webpage

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
This commit is contained in:
Zsolt Borbély
2016-08-26 16:38:24 +02:00
parent 0deac9f81c
commit 622f42e0a8
5 changed files with 336 additions and 165 deletions
+28 -21
View File
@@ -18,14 +18,14 @@ This guide is intended to introduce you to JerryScript embedding API through cre
#include "jerry-api.h"
int
main (int argc, char * argv[])
main (int argc, char *argv[])
{
const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);
bool ret_value = jerry_run_simple (script, script_size, JERRY_INIT_EMPTY);
return (ret_value ? 1 : 0);
return (ret_value ? 0 : 1);
}
```
@@ -50,7 +50,7 @@ Here we perform the same actions, as `jerry_run_simple`, while splitting into se
#include "jerry-api.h"
int
main (int argc, char * argv[])
main (int argc, char *argv[])
{
const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);
@@ -89,7 +89,7 @@ Our code is more complex now, but it introduces possibilities to interact with J
#include "jerry-api.h"
int
main (int argc, char * argv[])
main (int argc, char *argv[])
{
const jerry_char_t script_1[] = "var s = 'Hello, World!';";
const jerry_char_t script_2[] = "print (s);";
@@ -131,7 +131,7 @@ This way, we execute two independent script parts in one execution environment.
#include "jerry-api.h"
int
main (int argc, char * argv[]) {
main (int argc, char *argv[]) {
const jerry_char_t str[] = "Hello, World!";
const jerry_char_t script[] = "print (s);";
@@ -193,27 +193,27 @@ print_value (const jerry_value_t value)
{
if (jerry_value_is_undefined (value))
{
jerry_port_logmsg (stdout, "undefined");
jerry_port_console ("undefined");
}
else if (jerry_value_is_null (value))
{
jerry_port_logmsg (stdout, "null");
jerry_port_console ("null");
}
else if (jerry_value_is_boolean (value))
{
if (jerry_get_boolean_value (value))
{
jerry_port_logmsg (stdout, "true");
jerry_port_console ("true");
}
else
{
jerry_port_logmsg (stdout, "false");
jerry_port_console ("false");
}
}
/* Float value */
else if (jerry_value_is_number (value))
{
jerry_port_logmsg (stdout, "number");
jerry_port_console ("number");
}
/* String value */
else if (jerry_value_is_string (value))
@@ -223,16 +223,17 @@ print_value (const jerry_value_t value)
jerry_char_t str_buf_p[req_sz];
jerry_string_to_char_buffer (value, str_buf_p, req_sz);
str_buf_p[req_sz] = '\0';
jerry_port_logmsg (stdout, "%s", (const char *) str_buf_p);
jerry_port_console ("%s", (const char *) str_buf_p);
}
/* Object reference */
else if (jerry_value_is_object (value))
{
jerry_port_logmsg (stdout, "[JS object]");
jerry_port_console ("[JS object]");
}
jerry_port_logmsg (stdout, "\n");
jerry_port_console ("\n");
}
```
@@ -257,10 +258,10 @@ Shell operation can be described with the following loop:
#include "jerry-api.h"
#include "jerry-port.h"
static void print_value (const jerry_api_value_t);
static void print_value (const jerry_value_t);
int
main (int argc, char * argv[])
main (int argc, char *argv[])
{
bool is_done = false;
@@ -269,11 +270,11 @@ main (int argc, char * argv[])
while (!is_done)
{
char cmd [256];
char cmd[256] = {};
char *cmd_tail = cmd;
size_t len = 0;
jerry_port_logmsg (stdout, "> ");
jerry_port_console ("> ");
/* Read next command */
while (true)
@@ -292,6 +293,12 @@ main (int argc, char * argv[])
len++;
}
/* If the command is "quit", break the loop */
if (!strncmp (cmd, "quit\n", strlen ("quit\n")))
{
break;
}
jerry_value_t ret_val;
/* Evaluate entered command */
@@ -304,7 +311,7 @@ main (int argc, char * argv[])
{
/* Evaluated JS code thrown an exception
* and didn't handle it with try-catch-finally */
jerry_port_errormsg ("Unhandled JS exception occured: ");
jerry_port_console ("Unhandled JS exception occured: ");
}
print_value (ret_val);
@@ -346,7 +353,7 @@ get_msg_handler (const jerry_value_t func_value, /**< function object */
} /* get_msg_handler */
int
main (int argc, char * argv[])
main (int argc, char *argv[])
{
/* Initialize engine */
jerry_init (JERRY_INIT_EMPTY);
@@ -448,7 +455,7 @@ add_handler (const jerry_value_t func_value, /**< function object */
} /* add_handler */
int
main (int argc, char * argv[])
main (int argc, char *argv[])
{
/* Initialize engine */
jerry_init (JERRY_INIT_EMPTY);
@@ -514,4 +521,4 @@ Value of x is 17
## Further steps
For further API description, please visit [API Reference page](https://samsung.github.io/jerryscript/API/) on [JerryScript home page](https://samsung.github.io/jerryscript/).
For further API description, please visit [API Reference page](https://samsung.github.io/jerryscript/api-reference/) on [JerryScript home page](https://samsung.github.io/jerryscript/).