import { createPyroeisRuntime } from '@datamoc/mwg/mwl/pyroeis';
const runtime = createPyroeisRuntime({ modules: { rules: 'return { cost = 4 }' } });
let gold = 10;
runtime.set('game.side', runtime.createTable({
get: (key) => key === 'gold' ? gold : null,
set: (key, value) => { if (key === 'gold' && typeof value === 'number') gold = value; },
}));
runtime.defineFunction('game.balance', () => gold);
runtime.defineYieldingFunction('game.ask', (prompt) => [prompt]);
runtime.run('function dialogue() game.side.gold = game.side.gold - require("rules").cost; return game.ask("Continue?") end');
const dialogue = runtime.coroutine('dialogue');
console.log(dialogue.resume().values); // ['Continue?']
console.log(dialogue.resume([true]).values); // [true]
runtime.dispose();
Optional Lua integration host for a game-owned API, embedded modules and resumable handlers. The JSON-only ScriptHost stays independent. This host opens no system libraries, compiles text only and bounds calls, compilation and coroutine resumes. Tables read normally become arrays/objects/Maps; reference() and createTable() retain Lua identity explicitly. Host callbacks are trusted synchronous code. Proxy tables follow Lua's ordinary metatable rules: rawget/rawset bypass bindings. Neither heap size nor arbitrary host code is bounded.