Skip to the content.

Putting the language in the binary

The language JSON describes syntax. It belongs inside the program you ship.

Scripts stay outside. They are files you load at runtime. Designers can edit quest.mylang without a rebuild. They should not be able to change what fn means.

What you want

your-app/
  languages/mylang.json      edited in your repo
  src/main.cpp               #include the generated header, then add_language

At build time, CMake (or a script) turns mylang.json into a C++ string. At run time, you only call add_language once.

CMake (usual path)

This repo is already a subdirectory of your project:

rescripted_embed_language(your_app languages/mylang.json mylang)

That generates mylang_language.hpp in the build directory and adds the include path.

#include <ReScripted.h>
#include "mylang_language.hpp"

engine.add_language(
    rescripted::Language::compile(rescripted::embed::mylang));

The last argument to rescripted_embed_language is the C++ name: mylang → rescripted::embed::mylang.

Call add_language at startup. Do not compile the JSON every frame.

Without CMake

./scripts/embed_language.sh languages/mylang.json languages/mylang.hpp mylang

Then #include "languages/mylang.hpp" and compile that header with the rest of the app.

A string in source

Fine for tests. Same API:

engine.add_language(RESCRIPTED_LANGUAGE(R"({
  "name": "Mini",
  "extensions": [".mini"]
})"));

RESCRIPTED_LANGUAGE(...) is Language::compile over a string literal.

A JSON with only name and extensions compiles. Scripts will not parse let or fn until you add those keys. See Language JSON.

Reading JSON from disk at runtime

You can ifstream the file and pass the bytes to Language::compile. Then the game will not start if that file is missing, and a hand-edit can break every script. Prefer the generated header.

Embedding a script (not a language)

The same CMake helper can copy a .mini file into a string. That does not register it. You still add_library and pick the name. See Libraries.