Files
pyscript/pyscript.core/esm/runtime/wasmoon.js
Andrea Giammarchi 339e40063a WIP: Bringing PyScript.next PoC to the main project (#1507)
* kill unwrapped_remote (#1490)

* kill unwrapped_remote

* linting

* don't use callKwargs for python plugins

* fix tests and improve types

* Bringing PyScript.next PoC to the main project

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-05 21:52:28 +02:00

46 lines
1.4 KiB
JavaScript

import { fetchPaths, stdio, writeFileShim } from "./_utils.js";
const type = "wasmoon";
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
const worker = (method) =>
function (runtime, code, xworker) {
runtime.global.set("xworker", xworker);
return this[method](runtime, code);
};
export default {
type: [type, "lua"],
module: (version = "1.15.0") =>
`https://cdn.jsdelivr.net/npm/wasmoon@${version}/+esm`,
async engine({ LuaFactory, LuaLibraries }, config) {
const { stderr, stdout, get } = stdio();
const runtime = await get(new LuaFactory().createEngine());
runtime.global.getTable(LuaLibraries.Base, (index) => {
runtime.global.setField(index, "print", stdout);
runtime.global.setField(index, "printErr", stderr);
});
if (config.fetch) await fetchPaths(this, runtime, config.fetch);
return runtime;
},
run: (runtime, code) => runtime.doStringSync(code),
runAsync: (runtime, code) => runtime.doString(code),
runEvent(runtime, code, key) {
runtime.global.set("event", globalThis.__events.get(key));
return this.run(runtime, code);
},
runWorker: worker("run"),
runWorkerAsync: worker("runAsync"),
writeFile: (
{
cmodule: {
module: { FS },
},
},
path,
buffer,
) => writeFileShim(FS, path, buffer),
};
/* c8 ignore stop */