fantasy-console/cart_tools.ts

31 lines
634 B
TypeScript
Raw Normal View History

2023-05-01 18:42:55 -07:00
import faux from "./builtins.ts";
export type SheetType = "code" | "spritesheet" | "map" | "sfx" | "patterns" | "fonts";
export const parseCodeSheet = (sheet: string) => {
try {
new Function(sheet);
} catch (err) {
throw err;
}
// deno-lint-ignore no-explicit-any
const G: any = {...faux, faux, log: console.log};
const context = new Proxy(G, {
get: (target, prop) => {
return target[prop];
},
set: (target, prop, value) => {
target[prop] = value;
return true;
},
has: () => {
return true;
},
});
const fn = new Function("context", `
with (context) {
${sheet}
}
`);
return fn(context);
}