Requirements

Build

git clone https://github.com/steezer/emjs.git
cd emjs
mkdir -p build && cd build
cmake ..
cmake --build .

CMake targets produced:

TargetDescription
emjsCommand-line executable
emjs-coreCore interpreter static library
emjs-extsOptional extension modules static library
test_jsTest runner for script files

Install

cmake --install build --prefix /usr/local

Typical install layout:

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

OptionDefaultDescription
EMJS_OPTIMIZE_SIZEONEnable -Oz and size-focused flags
EMJS_ENGINE_DUMPOFFEnable verbose dump() debugging
BUILD_CONSOLE etc.ONToggle individual extension modules
Next: use the CLI tool to run scripts, or read the C++ API for embedding details.