Skip to content

Commit 001c3f1

Browse files
committed
Add webpack/browser support
1 parent 79b88d9 commit 001c3f1

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Farrell Raafi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
var mp = require('./lib/micropython.js');
2-
mp.onRuntimeInitialized();
2+
var browser = true;
3+
if (typeof window === 'undefined' && typeof importScripts === 'undefined') {
4+
mp.onRuntimeInitialized();
5+
browser = false;
6+
}
37
module.exports.init = global.mp_js_init;
48
module.exports.do_str = global.mp_js_do_str;
59
module.exports.init_repl = global.mp_js_init_repl;
610
module.exports.process_char = global.mp_js_process_char;
11+
if (browser) {
12+
var stdout = document.createElement('div');
13+
stdout.id = 'mp_js_stdout';
14+
stdout.style.display = 'none';
15+
stdout.addEventListener('print', function (event) {
16+
console.log(event.data);
17+
}, false);
18+
document.body.append(stdout);
19+
var interval = setInterval(() => {
20+
if (global.mp_js_init) {
21+
module.exports.init = global.mp_js_init;
22+
module.exports.do_str = global.mp_js_do_str;
23+
module.exports.init_repl = global.mp_js_init_repl;
24+
module.exports.process_char = global.mp_js_process_char;
25+
clearInterval(interval);
26+
}
27+
}, 0);
28+
}

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "micropython",
3+
"version": "1.0.1",
4+
"description": "A WASM module built from the official MicroPython port",
5+
"main": "index.js",
6+
"directories": {
7+
"lib": "lib"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/rafi16jan/micropython-wasm.git"
15+
},
16+
"keywords": [
17+
"python",
18+
"micropython",
19+
"wasm",
20+
"webassembly"
21+
],
22+
"author": "MicroPython",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/rafi16jan/micropython-wasm/issues"
26+
},
27+
"homepage": "https://github.com/rafi16jan/micropython-wasm#readme"
28+
}

0 commit comments

Comments
 (0)