Allow top level await
This commit is contained in:
parent
9cb77c7d59
commit
9b48560cce
8
index.ts
8
index.ts
@ -17,9 +17,9 @@ let game: any = null;
|
||||
|
||||
let mode: "play" | "edit" | "repl" = "repl";
|
||||
|
||||
addToContext("play", () => {
|
||||
addToContext("play", async () => {
|
||||
game = await runCode(getCodeSheet(0));
|
||||
mode = "play";
|
||||
game = runCode(getCodeSheet(0));
|
||||
game.init();
|
||||
});
|
||||
|
||||
@ -43,8 +43,8 @@ await mainloop(async (_t) => {
|
||||
} else {
|
||||
if (mode === "play") {
|
||||
if (game) {
|
||||
game.update();
|
||||
game.draw();
|
||||
await game.update();
|
||||
await game.draw();
|
||||
}
|
||||
frame();
|
||||
} else if (mode === "repl") {
|
||||
|
11
runcode.ts
11
runcode.ts
@ -13,6 +13,9 @@ export const getBuiltins = () => {
|
||||
return builtins;
|
||||
}
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const AsyncFunction = (async function () {}).constructor as any;
|
||||
|
||||
addToContext("eval", eval);
|
||||
|
||||
const context = new Proxy(G, {
|
||||
@ -31,18 +34,18 @@ const context = new Proxy(G, {
|
||||
},
|
||||
});
|
||||
|
||||
export const runCode = (code: string) => {
|
||||
export const runCode = async (code: string) => {
|
||||
try {
|
||||
new Function(code);
|
||||
new AsyncFunction(code);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const fn = new Function("context", `
|
||||
const fn = new AsyncFunction("context", `
|
||||
with (context) {
|
||||
${code}
|
||||
}
|
||||
`);
|
||||
return fn(context);
|
||||
return await fn(context);
|
||||
}
|
||||
|
||||
export const evalCode = (code: string) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user