@@ -168,7 +168,7 @@ This method will be implemented in C and will be called from the JavaScript code
168168For this a few extra API methods are required:
169169
170170-  ` jerry_current_realm ` 
171- -  ` jerry_string_sz ` 
171+ -  ` jerry_sz_ascii ` 
172172-  ` jerry_object_set ` 
173173-  ` jerry_function_external ` 
174174
@@ -207,7 +207,7 @@ main (void)
207207    /*  Get the "global" object * /
208208    jerry_value_t global_object = jerry_current_realm ();
209209    /*  Create a "print" JS string * /
210-     jerry_value_t property_name_print = jerry_string_sz  ("print");
210+     jerry_value_t property_name_print = jerry_sz_ascii  ("print");
211211    /*  Create a function from a native C method (this function will be called from JS) * /
212212    jerry_value_t property_value_func = jerry_function_external (print_handler);
213213    /*  Add the "print" property with the function value to the "global" object * /
@@ -326,7 +326,7 @@ main (void)
326326    /*  Get the "global" object * /
327327    jerry_value_t global_object = jerry_current_realm ();
328328    /*  Create a "print" JS string * /
329-     jerry_value_t property_name_print = jerry_string_sz  ("print");
329+     jerry_value_t property_name_print = jerry_sz_ascii  ("print");
330330    /*  Create a function from a native C method (this function will be called from JS) * /
331331    jerry_value_t property_value_func = jerry_function_external (print_handler);
332332    /*  Add the "print" property with the function value to the "global" object * /
@@ -393,9 +393,17 @@ In this example the following extension methods are used:
393393
394394In further examples this "print" handler will be used.
395395
396+ The ` api-example-6.c `  file should contain the following code:
397+ 
398+ [ doctest ] : #  ( ) 
399+ 
396400``` c 
401+ #include  < stdio.h> 
402+ 
397403#include  " jerryscript.h" 
404+ 
398405#include  " jerryscript-ext/handlers.h" 
406+ #include  " jerryscript-ext/properties.h" 
399407
400408int 
401409main  (void)
@@ -407,7 +415,7 @@ main (void)
407415  jerry_init (JERRY_INIT_EMPTY);
408416
409417  /*  Register 'print' function from the extensions to the global object * /
410-   jerryx_register_global ("print", jerryx_handler_print);
418+   jerryx_register_global (jerry_sz_ascii ( "print") , jerryx_handler_print);
411419
412420  /*  Setup Global scope code * /
413421  jerry_value_t parsed_code = jerry_parse (script, script_size, NULL);
@@ -470,14 +478,14 @@ main (void)
470478  jerry_init (JERRY_INIT_EMPTY);
471479
472480  /*  Register 'print' function from the extensions * /
473-   jerryx_register_global ("print", jerryx_handler_print);
481+   jerryx_register_global (jerry_sz_ascii ( "print") , jerryx_handler_print);
474482
475483  /*  Getting pointer to the Global object * /
476484  jerry_value_t global_object = jerry_current_realm ();
477485
478486  /*  Constructing strings * /
479-   jerry_value_t prop_name = jerry_string_sz  ("my_var");
480-   jerry_value_t prop_value = jerry_string_sz  ("Hello from C!");
487+   jerry_value_t prop_name = jerry_sz_ascii  ("my_var");
488+   jerry_value_t prop_value = jerry_sz_ascii  ("Hello from C!");
481489
482490  /*  Setting the string value as a property of the Global object * /
483491  jerry_value_t set_result = jerry_object_set (global_object, prop_name, prop_value);
@@ -729,7 +737,7 @@ main (void)
729737  jerry_init (JERRY_INIT_EMPTY); 
730738
731739  /* Register 'print' function from the extensions */ 
732-   jerryx_register_global ("print", jerryx_handler_print); 
740+   jerryx_register_global (jerry_sz_ascii ( "print") , jerryx_handler_print); 
733741
734742  while (!is_done) 
735743  { 
@@ -808,10 +816,8 @@ In this example (`api-example-9.c`) an object with a native function is added to
808816#include  " jerryscript-ext/handlers.h" 
809817#include  " jerryscript-ext/properties.h" 
810818
811- struct  my_struct
812- {
813-   const char * msg;
814- } my_struct;
819+ 
820+ jerry_string_t  my_struct;
815821
816822/* *
817823 * Get a string from a native object 
@@ -821,7 +827,7 @@ get_msg_handler (const jerry_call_info_t *call_info_p, /**< call information */
821827                 const jerry_value_t * args_p, /** < function arguments * /
822828                 const jerry_length_t args_cnt) /** < number of function arguments * /
823829{
824-   return jerry_string_sz  (my_struct.msg );
830+   return jerry_string_ascii  (my_struct.ptr, my_struct.size );
825831} /*  get_msg_handler * /
826832
827833int
@@ -831,10 +837,13 @@ main (void)
831837  jerry_init (JERRY_INIT_EMPTY);
832838
833839  /*  Register 'print' function from the extensions * /
834-   jerryx_register_global ("print", jerryx_handler_print);
840+   jerryx_register_global (jerry_sz_ascii ( "print") , jerryx_handler_print);
835841
836842  /*  Do something with the native object * /
837-   my_struct.msg = "Hello, World!";
843+   {
844+     static const jerry_string_t hello = { JERRY_ZSTR_ARG ("Hello, World!") };
845+     my_struct = hello;
846+   }
838847
839848  /*  Create an empty JS object * /
840849  jerry_value_t object = jerry_object ();
@@ -843,7 +852,7 @@ main (void)
843852  jerry_value_t func_obj = jerry_function_external (get_msg_handler);
844853
845854  /*  Set the native function as a property of the empty JS object * /
846-   jerry_value_t prop_name = jerry_string_sz  ("myFunc");
855+   jerry_value_t prop_name = jerry_sz_ascii  ("myFunc");
847856  jerry_value_free (jerry_object_set (object, prop_name, func_obj));
848857  jerry_value_free (prop_name);
849858  jerry_value_free (func_obj);
@@ -852,7 +861,7 @@ main (void)
852861  jerry_value_t global_object = jerry_current_realm ();
853862
854863  /*  Add the JS object to the global context * /
855-   prop_name = jerry_string_sz  ("MyObject");
864+   prop_name = jerry_sz_ascii  ("MyObject");
856865  jerry_value_free (jerry_object_set (global_object, prop_name, object));
857866  jerry_value_free (prop_name);
858867  jerry_value_free (object);
@@ -928,7 +937,7 @@ add_handler (const jerry_call_info_t *call_info_p, /**< call information */
928937  /*  Note: that the argument count check is ignored for the example's case * /
929938
930939  /*  Get 'this.x' * /
931-   jerry_value_t prop_name = jerry_string_sz  ("x");
940+   jerry_value_t prop_name = jerry_sz_ascii  ("x");
932941  jerry_value_t x_val = jerry_object_get (call_info_p->this_value, prop_name);
933942
934943  if (!jerry_value_is_exception (x_val))
@@ -958,7 +967,7 @@ main (void)
958967  jerry_init (JERRY_INIT_EMPTY);
959968
960969  /*  Register 'print' function from the extensions * /
961-   jerryx_register_global ("print", jerryx_handler_print);
970+   jerryx_register_global (jerry_sz_ascii ( "print") , jerryx_handler_print);
962971
963972  /*  Create a JS object * /
964973  const jerry_char_t my_js_object[ ]  = " \ 
@@ -983,7 +992,7 @@ main (void)
983992  jerry_value_t add_func_obj = jerry_function_external (add_handler);
984993
985994  /*  Set the native function as a property of previously created MyObject * /
986-   jerry_value_t prop_name = jerry_string_sz  ("add2x");
995+   jerry_value_t prop_name = jerry_sz_ascii  ("add2x");
987996  jerry_value_free (jerry_object_set (my_js_obj_val, prop_name, add_func_obj));
988997  jerry_value_free (add_func_obj);
989998  jerry_value_free (prop_name);
@@ -1058,7 +1067,7 @@ main (void)
10581067  jerry_init (JERRY_INIT_EMPTY);
10591068
10601069  /*  Register the print function * /
1061-   jerryx_register_global ("print", jerryx_handler_print);
1070+   jerryx_register_global (jerry_sz_ascii ( "print") , jerryx_handler_print);
10621071
10631072  /*  Evaluate the script * /
10641073  jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
0 commit comments