Scripting & runtime · embedding
Embed a persistent Nift runtime.
nift::Engine is the supported C++ host for scripts, expressions and rendering. The stable C ABI is version 1.1, with maintained Python, Node, Go and C# bindings built on that boundary.
#include <nift/engine.h>
nift::Engine engine;
auto program = engine.execute("x := 40; return x + 2;");
auto value = engine.evaluate("x + 1");
engine.set("site_name", "Example");
engine.register_function("native_mul", [](const std::vector<nift::Value>& a) {
return nift::Value(a.at(0).as_int() * a.at(1).as_int());
}); execute() starts a complete program and establishes persistent script globals/functions; evaluate() observes the most recent runtime; call() invokes a named Nift function. Rendering supports in-memory text, filesystem sources, partials, composed page/template renders, and project-aware tracked pages. Engine defaults and per-render Context overlays expose host values; hosts may register typed native functions, loaders, environment providers, and a per-Engine platform.
Isolation, concurrency and teardown
Engine instances own isolated state, environment/platform configuration, and scripting runtimes. Operations on one Engine's persistent script runtime are serialized. Configure an Engine before concurrent rendering: concurrent renders are supported, but mutation must not race active renders. Destroying an Engine waits or defers safely around its in-flight work; host callbacks and result objects must follow their documented ownership.
C ABI 1.1 and maintained bindings
The C API reports nift_abi_version() == "1.1" and exposes Engine lifecycle, values, scripts/evaluation, rendering, host callbacks, buffers and errors through explicit ownership functions. The repository maintains direct C++ and C consumers plus Python, Node, Go and C# bindings. Consult the matching binding package for language-specific disposal and callback rules; do not mix objects across Engines.