-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathskulpt.js
48 lines (43 loc) · 1.2 KB
/
skulpt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function outf(text) {
addCmd(text.replace("\n", ""))
console.log(text)
}
function builtinRead(x) {
if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
throw "File not found: '" + x + "'";
return Sk.builtinFiles["files"][x];
}
function runit() {
var prog = `
class _Entity:
def __init__(self, x, y, sprite):
self.x=x
self.y=y
self.id=str(id(self))
print(f"addEntity:{self.id},{x},{y},{sprite}")
def move(self, dir):
print(f"move:{self.id},{dir}")
def say(self, text):
print(f"say:{self.id},{text}")
class Bunny(_Entity):
def __init__(self, x, y):
super().__init__(x, y, "bunny")
class Cat(_Entity):
def __init__(self, x, y):
super().__init__(x, y, "cat")
\n` + editor.getValue();
Sk.configure({
output: outf,
read: builtinRead,
execLimit: 5000,
});
var myPromise = Sk.misceval.asyncToPromise(function () {
return Sk.importMainWithBody("<stdin>", false, prog, true);
});
myPromise.then(function (mod) {
console.log('success');
},
function (err) {
console.log(err.toString());
});
}