almost a real repl
This commit is contained in:
29
sheet.ts
29
sheet.ts
@ -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);
|
Reference in New Issue
Block a user