Getting Started
Build Emjs from source, install artifacts, and embed the engine in a C++ application.
Requirements
- C++17 compatible compiler (GCC, Clang, MSVC)
- CMake 3.14+
- No third-party runtime dependencies for the core engine
Build
git clone https://github.com/steezer/emjs.git
cd emjs
mkdir -p build && cd build
cmake ..
cmake --build .
CMake targets produced:
| Target | Description |
|---|---|
emjs | Command-line executable |
emjs-core | Core interpreter static library |
emjs-exts | Optional extension modules static library |
test_js | Test runner for script files |
Install
cmake --install build --prefix /usr/local
Typical install layout:
/usr/local/bin/emjs/usr/local/lib/libemjs-core.a/usr/local/lib/libemjs-exts.a/usr/local/include/emjs/*.h
Minimal embed example
#include "engine.h"
#include <cstdio>
using namespace Emjs;
int main() {
char mem[4096] = {0};
JsEngine* js = JsEngine::create(mem, sizeof(mem));
if (!js) return 1;
JsValue r = js->eval("let x=3; let y=4; x*y + 1;");
std::printf("%s\n", js->str(r)); // prints 13
JsEngine::destroy(js);
return 0;
}
Linking in your project
# Example compile line
c++ -std=c++17 app.cpp -I/path/to/emjs/include/emjs \
-L/path/to/emjs/lib -lemjs-core -lemjs-exts
Project layout
src/
core.h / core.cpp # lexer, parser, interpreter, GC
engine.h / engine.cpp # public C++ API
internal.h / internal.cpp
extension/ # optional modules (console, math, json...)
app.cpp # CLI source
tests/script/ # example JavaScript files
Build options
| Option | Default | Description |
|---|---|---|
EMJS_OPTIMIZE_SIZE | ON | Enable -Oz and size-focused flags |
EMJS_ENGINE_DUMP | OFF | Enable verbose dump() debugging |
BUILD_CONSOLE etc. | ON | Toggle individual extension modules |