forked from PythonJS/PythonJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathempythoned-webworker.js
More file actions
42 lines (35 loc) · 970 Bytes
/
empythoned-webworker.js
File metadata and controls
42 lines (35 loc) · 970 Bytes
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
(function () {
self.console = {
log: function () {}
};
self.prompt = function () {
return 'Input not supported in demo';
};
importScripts('empythoned.js');
// https://github.com/kripken/emscripten/wiki/Filesystem-API
FS.createLazyFile(".", "python_to_pythonjs.py", "./python_to_pythonjs.py",
true,false
);
FS.createLazyFile(".", "pythonjs.py", "./pythonjs.py",
true,false
);
FS.createLazyFile(".", "ministdlib.py", "./ministdlib.py",
true,false
);
Python.initialize(null, function(chr) {
if (chr !== null)
postMessage(String.fromCharCode(chr));
});
var on_message = function (e) {
if (Python.isFinished(e.data)) {
var result = Python.eval(e.data);
if (result !== null && result !== undefined) {
postMessage('\n--------------------------\nResult: ' + result);
}
} else {
postMessage('\nCommand not finished.\n');
}
};
addEventListener('message', on_message, false);
postMessage('Empythoned Ready\n');
})();