RATJS is a small javascript/ecmascript interpreter written in C. You can use it to run javascript programs, or embed it into your program as a script engine
RATJS use GNU make to build the source code. The following libraries and headers are required for building:
Show all the configuration options:
$ make help
Configure the project.
$ make config
Build the libraries and executable programs.
$ make
Install the libraries and executable programs.
$ make install
Clear intermediate files.
$ make clean
Clear the build directory.
$ make dist-clean
To build RATJS on Windows, you need setup MinGW environment.
Configure the project.
$ make ARCH=win config
Build the libraries and executable programs.
$ make
Install the libraries and executable programs.
$ make install
Clear intermediate files.
$ make clean
Clear the build directory.
$ make dist-clean
Run program "ratjs" to execute your javascript program.
To run the "js" script file:
$ ratjs -s your_script.js arguments...
"ratjs" will load and execute the script "your_script.js". If the script has defined "main" function, the function will be invoked and "arguments" will be passed to it as the arguments.
To run the "js" as ECMA262 module:
$ ratjs your_module.js arguments
"ratjs" will load, link and execute the module "your_module.js". If the module has defined "main" function, the function will be invoked and "arguments" will be passed to it as the arguments.
To read script string from argument and invoke "eval()" function to execute it:
$ ratjs -e "script_string"
To show options of the program "ratjs":
$ ratjs --help
In your source code, include header file "ratjs.h". Then invoke RATJS APIs to load and execute the script.
#include <ratjs.h>
...
RJS_Runtime *rt;
RJS_Value *source, *script;
rt = rjs_runtime_new();
rjs_realm_load_extension(rt, NULL);
source = rjs_value_stack_push(rt);
script = rjs_value_stack_push(rt);
rjs_string_from_enc_chars(rt, source, "print(\"hello, world!\")", -1, NULL);
rjs_script_from_string(rt, script, source, NULL, RJS_FALSE);
rjs_script_evaluation(rt, script, NULL);
rjs_runtime_free(rt);
Link your program with library "libratjs".
$ gcc -o your_program -lratjs -lm your_program_source.c
Run command "doxygen" to generate API document of RATJS.
You can refer to the relevant programs in the "demo" directory to study how to embed RATJS to your program.
You can use other compiler language to develop the native module to extend the javascript's function. Please refer to njsgen-native module generator to quickly build native modules.
Extension functions and objects
This project is licensed under the terms of the MIT license.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. Open source ecosystem
2. Collaboration, People, Software
3. Evaluation model