---
[](README-zh.md) [](https://www.apache.org/licenses/LICENSE-2.0) [](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml)    [](https://coveralls.io/github/Tencent/ScriptX)

ScriptX is a script engine abstraction layer. A variety of script engines are encapsulated on the bottom and a unified API is exposed on the top, so that the upper-layer caller can completely isolate the underlying engine implementation (back-end).
ScriptX not only isolates several JavaScript engines, but can even isolate different scripting languages, so that **the upper layer can seamlessly switch between scripting engine and scripting language without changing the code**.
In ScriptX terminology, "front-end" refers to the external C++ API, and "back-end" refers to different underlying engines. The currently implemented back-ends include: V8, node.js, JavaScriptCore, WebAssembly, Lua.
# States
| backend | language | version | states |
| :----: | :----: | :----: | :----: |
| V8 | JavaScript | 7.4+ | done |
| JavaScriptCore | JavaScript | 7604.1.38.0.7+ (iOS 10+/macOS10.12+) | done |
| Node.js | JavaScript | 14.x+ | done |
| QuickJs | JavaScript | 2021-03-27 | done |
| WebAssembly | JavaScript | Emscripten-2.0.5+ | done |
| Lua | Lua | 5.4+ | done |
| CPython | Python | | todo |
| YARV | Ruby | | todo |
| Mono | C# | | todo |
# Introduction
The interface of ScriptX uses modern C++ features. And to be 100% in line with the C++ standard, completely cross-platform.
All APIs are exposed in the `ScriptX.h` aggregate header file.
Design goals: **Multi-language** | **Multi-engine implementation** | **High performance** | **API easy to use** | **Cross-platform**
# First impression
We use a relatively complete code to leave an overall impression of ScriptX.
```c++
EngineScope enter(engine);
try {
engine->eval("function fibo(x) {if (x<=2) return 1; else return fibo(x-1) + fibo(x-2) }");
Local fibo = engine->get("fibo").asFunction();
Local ret = fibo.call({}, 10);
ret.asNumber().toInt32() == 55;
auto log = Function::newFunction(
[](const std::string& msg) {
std::cerr << "[log]: "<< msg << std::endl;
});
// or use: Function::newFunction(std::puts);
engine->set("log", log);
engine->eval("log('hello world');");
auto json = engine->eval(R"( JSON.parse('{"length":1,"info":{"version": "1.18","time":132}}'); )")
.asObject();
json.get("length").asNumber().toInt32() == 1;
auto info = json.get("info").asObject();
info.get("version").asString().toString() == "1.18";
info.get("time").asNumber().toInt32() == 132;
Local