almost a real repl

This commit is contained in:
dylan
2023-05-03 15:17:27 -07:00
parent 7de521bd39
commit 1482288b0c
6 changed files with 308 additions and 35 deletions

View File

@ -1,5 +1,5 @@
import faux from "./builtins.ts";
import { getCart } from "./cart.ts";
import { runCode, addToContext } from "./runcode.ts";
export type SheetType = "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts";
@ -9,30 +9,7 @@ const getSheet = (n: number) => {
export const codeSheet = (sheet: number) => {
const code = getSheet(sheet);
try {
new Function(code);
} catch (err) {
throw err;
}
const fn = new Function("context", `
with (context) {
${code}
}
`);
return fn(context);
return runCode(code);
}
// deno-lint-ignore no-explicit-any
const G: any = {...faux, faux, log: console.log, code_sheet: codeSheet};
const context = new Proxy(G, {
get: (target, prop) => {
return target[prop];
},
set: (target, prop, value) => {
target[prop] = value;
return true;
},
has: () => {
return true;
},
});
addToContext("code_sheet", codeSheet);