Go to the first, previous, next, last section, table of contents.


JavaScript API

Interpreter Handling

Function: const char * js_version ()
Return a string that describes the JavaScript interpreter version number. The returned string is in format "major.minor.patch", where major, minor, and patch are integer numbers.

Function: void js_init_default_options (JSInterpOptions *options)
Initialize the interpreter options options to the default values. These are the same values that are used in the interpreter creation, if the argument options of js_create_interp() is NULL.

Function: JSInterpPtr js_create_interp (JSInterpOptions *options)
Create a new JavaScript interpreter. The function returns an interpreter handle that must be passed to all other interpreter API functions. The argument options specify additional options for the interpreter. If the argument is NULL, the default values are used. If the interpreter creation fails -- due insufficient memory resources -- the function return value NULL.

Function: void js_destroy_interp (JSInterpPtr interp)
Destroy interpreter interp and free all resources the interpreter has allocated. The handle interp must not be used after this function.

Function: const char * js_error_message (JSInterpPtr interp)
Return an error message of the latest error in interpreter interp.

Function: void js_result (JSInterpPtr interp, JSType *result_return)
Get the result of the latest evaluation or execution in interpreter interp. The result is returned in result_return. All data, returned in result_return, belongs to the interpreter. The caller must not modify or changed it in any ways.

Function: void js_set_var (JSInterpPtr interp, char *name, JSType *value)

Function: void js_get_var (JSInterpPtr interp, char *name, JSType *value)

Function: void js_get_options (JSInterpPtr interp, JSInterpOptions *options)
Get the options of interpreter interp to options.

Function: void js_set_options (JSInterpPtr interp, JSInterpOptions *options)
Modify the options of interpreter interp according to options.

Evaluation and Compilation

Function: int js_eval (JSInterpPtr interp, char *code)
Evaluate JavaScript code code with interpreter interp. The argument code is NUL-terminated a C-string holding the JavaScript code. The function returns 1 if the operation was successful or 0 otherwise. If the evaluation failed, the error message can be retrieved with function js_error_message().

Function: int js_eval_data (JSInterpPtr interp, char *data, unsigned int datalen)
Evaluate JavaScript code data, datalen with interpreter interp.

Function: int js_eval_file (JSInterpPtr interp, char *filename)
Evaluate file filename with interpreter interp. The file filename can contain JavaScript or byte-code.

Function: int js_eval_javascript_file (JSInterpPtr interp, char *filename)
Evaluate JavaScript code file filename with interpreter interp.

Function: int js_execute_byte_code_file (JSInterpPtr interp, char *filename)
Execute a byte-code file filename with interpreter interp.

Function: int js_apply (JSInterpPtr interp, char *name, unsigned int argc, JSType *argv)
Call function name with arguments argc, argv. The return value of the function name can be retrieved with the js_result() function.

Function: int js_compile (JSInterpPtr interp, char *input_file, char *assembler_file, char *byte_code_file)
Compile JavaScript input file input_file. If the argument assembler_file is not NULL, the generated assembler code is saved to the file, specified by the argument. If the argument byte_code_file is not NULL, the generated byte-code data is svaed to the file, specified by the argument.

Function: int js_compile_to_byte_code (JSInterpPtr interp, char *input_file, unsigned char **bc_return, unsigned int *bc_len_return);
Compile JavaScript file input_file to byte-code and return the resulting byte-code data in bc_return, bc_len_return. The returned byte-code data bc_return belongs to the interpreter and it must be saved by the caller before any other JS functions is called. If the data is not saved, its contents will be invalidated at the next garbage collection.

Function: int js_compile_data_to_byte_code (JSInterpPtr interp, char *data, unsigned int datalen, unsigned char **bc_return, unsigned int *bc_len_return);

Compile JavaScript code data, datalen to byte-code and return the resulting byte-code data in bc_return, bc_len_return.

Function: int js_execute_byte_code (JSInterpPtr interp, unsigned char *bc, unsigned int bc_len);

Execute byte-code data bc, bc_len. The byte-code data is the contents of a byte-code file, or a copy of the data returned by the js_compile_to_byte_code() or js_compile_data_to_byte_code() functions.

Note! You can't use the data from the js_compile_to_byte_code(), js_compile_data_to_byte_code() functions as an input for this function. You must take a private copy of the data and pass that copy to the function:

if (js_compile_to_byte_code (interp, file, &bc, &bclen))
  {
    char *bc_copy = xmalloc (bclen);
    memcpy (bc_copy, bc, bclen);
    js_execute_byte_code (interp, bc_copy, bclen);
    xfree (bc_copy);
  }

Type Handling

Function: void js_type_make_string (JSInterpPtr interp, JSType *type, unsigned char *data, unsigned int length)

Function: void js_type_make_array (JSInterpPtr interp, JSType *type, unsigned int length)

Global Methods

Function: void js_create_global_method (JSInterpPtr interp, char *name, JSGlobalMethodProc proc, void *context, JSFreeProc context_free_proc)

Classes

Function: JSClassPtr js_class_create (void *class_context, JSFreeProc class_context_destructor, int no_auto_destroy, JSConstructor constructor)

Create a new class with class context data class_context. The context data is destroyed with class_context_destructor. If the argument no_auto_destroy is not 0, the JavaScript interpreter will not destroy the class when the interpreter is destroyed. In that case, it is the caller's responsibility to call js_class_destroy() for the returned class handle, after the interpreter has been destroyed. If the argument constructor is not NULL, it is used to instantiate the class when a `new class (args[...]);' expression is evaluated in the JavaScript code.

Function: void js_class_destroy (JSClassPtr cls)

Function: JSVoidPtr js_class_context (JSClassPtr cls)

Function: int js_class_define_method (JSClassPtr cls, char *name, unsigned int flags, JSMethodProc method)

Function: int js_class_define_property (JSClassPtr cls, char *name, unsigned int flags, JSPropertyProc property)

Function: int js_define_class (JSInterpPtr interp, JSClassPtr cls, char *name)

Function: int js_instantiate_class (JSInterpPtr interp, JSClassPtr cls, void *instance_ctx, JSFreeProc instance_ctx_destructor, JSType *result_return)

Function: const JSClassPtr js_lookup_class (JSInterpPtr interp, char *name)

Function: int js_isa (JSInterpPtr interp, JSType *object, JSClassPtr cls, void **instance_context_return)

Check if object object is an instance of class cls. The function returns a boolean success status. If the argument instance_context_return is not NULL, it will be set to the instance context of object object.

Modules

Function: int js_define_module (JSInterpPtr interp, JSModuleInitProc init_proc)


Go to the first, previous, next, last section, table of contents.