A generic, sandboxed Luau host: VM lifecycle, luaL_sandbox, a CPU-time watchdog, a per-engine heap cap, bytecode compile/load, and a QVariant↔Lua marshalling layer, with no knowledge of tiling or any other domain.
Phosphor runs user-authored scripts (tiling algorithms today, other shell surfaces later). This library owns the embedding of Luau so each domain binding can stay small. A binding marshals its params into QVariant, calls a script, and reads the result back. It deliberately knows nothing about what the scripts compute.
| Type | Purpose |
|---|---|
| PhosphorScripting::LuauEngine | The sandboxed VM, with a QVariant-only API (init / runPrelude / sandbox / loadModule / releaseModule / moduleField / hasFunction / callModule) |
| PhosphorScripting::LuauWatchdog | Shared CPU-deadline supervisor that aborts runaway scripts via the interrupt callback |
#include <PhosphorScripting/LuauEngine.h>
#include <PhosphorScripting/LuauWatchdog.h>
using namespace PhosphorScripting;
auto watchdog = std::make_shared<LuauWatchdog>();
LuauEngine engine(watchdog); // default 64 MiB heap cap
engine.init();
engine.runPrelude(QStringLiteral("pluau"), preludeSource); // install host globals
engine.sandbox(); // freeze globals + stdlib
QString err;
const int mod = engine.loadModule(QStringLiteral("script"), source, &err);
const auto out = engine.callModule(mod, QStringLiteral("tile"), {ctx}, 100 /*ms*/);
if (out.status == LuauEngine::CallStatus::Ok) {
// out.result is a QVariant marshalled from the script's return value.
}Luau is built from source as part of this library, from the archive cmake/PhosphorDependencies.cmake pins by version, URL and SHA-256. A normal configure downloads it once with CPM into .cache/cpm. An offline build (every distro package) passes -DPHOSPHOR_DEPS_ARCHIVES=<dir> with the archive in it, and nothing is downloaded. Pass -DPHOSPHOR_SYSTEM_LUAU=ON to link a system-provided Luau instead. The Luau libraries are linked PRIVATE and the VM is built PIC, with -fexceptions force-enabled and unity builds disabled on the vendored targets only (Luau needs C++ unwinding for lua_pcall, and its file-local symbol names collide under unity batching). This is independent of the project's global build settings.