Embedding the language JSON (agent instructions)
The language definition must be compiled into the user’s program.
Option A — raw string in a .cpp
Good for tiny configs and tests. Still emit a complete template-shaped JSON if you are creating a real language; the string can live in languages/mylang.json and be #included only after you generate a header (option B). For a first compile check you may start with a literal:
#include <ReScripted.h>
static constexpr std::string_view kMyLang = R"json(
{
"name": "MyLang",
"extensions": [".ml"]
}
)json";
engine.add_language(rescripted::Language::compile(kMyLang));
A config with only name + extensions compiles. A real language still needs the full template values.
Option B — embed_language.sh (preferred)
In the user’s project (or using ReScripted’s script if they have the repo):
path/to/ReScripted/scripts/embed_language.sh languages/mylang.json languages/mylang.hpp mylang
Produces:
namespace rescripted { namespace embed {
inline constexpr std::string_view mylang = R"rescripted_lang( ... )rescripted_lang";
}}
#include <ReScripted.h>
#include "languages/mylang.hpp"
engine.add_language(rescripted::Language::compile(rescripted::embed::mylang));
Option C — CMake
If their CMake already has ReScripted:
rescripted_embed_language(their_app languages/mylang.json mylang)
This needs RESCRIPTED_EMBED_SCRIPT (set by ReScripted’s CMake). Generated header: ${CMAKE_CURRENT_BINARY_DIR}/rescripted_embed/mylang_language.hpp. Add that include directory is done by the function.
Host CMakeLists sketch
add_subdirectory(third_party/ReScripted)
add_executable(game src/main.cpp stdlib/math.c++)
target_link_libraries(game PRIVATE ReScripted::ReScripted)
rescripted_embed_language(game languages/mylang.json mylang)
Or copy only include/ReScripted.h and call embed_language.sh from a custom command.
CMake must not register libraries. The host calls engine.add_library("app.math", rescripted::library::math). See libraries.md.
After embedding
engine.add_language(...)once at startup.- Bind host functions the JSON advertised.
load_filescripts by extension.
Do not re-parse the JSON from disk on every frame. Compile it in.